Reputation: 990
Please Help. I am trying to create the query in mongodb like (in MySql):
SELECT * FROM user WHERE user_id = '1' AND (type = 'admin' OR type = 'requester') ORDER BY user_id DESC
How do I convert this query into mongodb find({})?
Upvotes: 1
Views: 113
Reputation: 557
Check this,
db.user.find({user_id:"1",$or:[{"type":"admin"},{"type":"manager"}]})
Upvotes: 1
Reputation: 1696
I'd use $in instead of $or since only a single field is involved:
db.user.find({
user_id:"1",
type: {$in:["admin","requester"]}
}).sort({"user_id":-1});
Upvotes: 1