16

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}}])

2 Answers 2

48

try this:

db.student.find({ u1 : { $gt :  30, $lt : 60}});
4

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

1
  • For me, this syntax also works when interfacing MongoDB via mongo-express advanced query, while the accepted answer does not.
    – ra0
    Feb 28 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy