'Find documents with $gte or $lte which has numbers as string values in arrays
I have a MongoDB collection that contains documents as follows:
{
"_id": ObjectId(.....),
"name": "John",
"contacts": [
{
"name": "henry",
"age": "22"
},
{
"name": "merry",
"age": "12"
}
]
}
I want to find documents which have contacts.age is less than 20. I tried the following mongo query but had no luck. Anyone can help me out?
document.Users.find({'$expr':{'$lte': [{'$toInt':'$contacts.age'}, '20'] }})
Above query gives following error:
Query failed with error code 241 and error message 'Executor error during find command ::
caused by ::
Unsupported conversion from array to int in $convert with no onError value' on server
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
