Home > Blockchain >  Optional find() parameter in MongoDB when searching for values
Optional find() parameter in MongoDB when searching for values

Time:09-23

Basically what I am trying to do is say to my query that I want all of the users that have isBoosted = True to be first and after that, all others.

Thank You!

CodePudding user response:

you can use the method sort to order descending because true=1 and false=0 like this:

db.users.find().sort("isBoosted", -1)

Or

db.users.find([your filter criteria]).sort("isBoosted", -1)
  • Related