I have a db named student and I want to select the values between 30 and 60 from a column named u1. This is the query I used,but it shows some error
db.student.find($and:[{u1:{$gt:30}},{u1:{$lt:60}}])
You could also try this:
db.students.find({$and:[{u1:{$gt:30}},{u1:{$lt:60}}]})
The above statement will display the value of the field u1 which are in between 30 and 60
For all except the most simple queries, I find the aggregation pipeline gives you "more room to grow" and of course many more functions are available to you in the agg pipeline that cannot be used in $find:
db.students.aggregate([
{$match: {$expr: {$and: [
{$gt: ['$u1', 20]}
,{$lt: ['$u1', 23]}
] }
}}
])