-
Type: Bug
-
Resolution: Community Answered
-
Priority: Major - P3
-
Affects Version/s: 2.2.4
-
Component/s: None
-
Environment:OS:
node.js / npm versions:
Additional info:
-
Not Needed
-
Developer Tools
Problem Statement
Consider the collection sales
[
{
_id: ObjectId('668ea197ccaa7da04b117b7c'),
results: [ 82, 85, 88 ]
},
{
_id: ObjectId('668ea197ccaa7da04b117b7d'),
results: [ 75, 88, 89 ]
}
]
Q: Find all the documents where there contains at least one element in array result such that : 80<=ele<85
Implicit version used:
db.scores.find({ results: { $elemMatch:
} })
Explicit Version ($and) used
db.scores.find({ results: { $elemMatch: { $and: [
, { $gte: 80 }] } } })
Error:MongoServerError[BadValue]: unknown top level operator: $lt. If you have a field name that starts with a '$' symbol, consider using $getField or $setField.
We can't do something like below
db.scores.find({ $and: [ { results: { $elemMatch:
{ $gte: 80 }} }, { results: { $elemMatch:
{ $lt: 85 }} }] })
as it will give both the records