I am writting the following query to retrive the records based on 2 conditions.Executing the Query giving me error:
> db.employee.find({age:{$lt:32}},{salary:{$lt:40000}})
Here is the error Message:
Error: error: {
"ok" : 0,
"errmsg" : "Expression $lt takes exactly 2 arguments. 1 were passed in.",
"code" : 16020,
"codeName" : "Location16020"
}
To do a find query based in two conditions, you need to do in the same query object.
Note that you are doing:
find({obj1},{obj2}
But second parameter into find method is for projection (docs)
So you need this query:
db.collection.find({
"age": {
"$lt": 32
},
"salary": {
"$lt": 40000
}
})
Note how there is only one object with two fields: age and salary.
Something like find( { age:{}, salary:{}} ).
Example here