Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a OR operation query in nodejs/MongoDB?

I am trying to query my mongodb but I don't know which row my data is under so i am trying to querying both rows with parameters, is this syntax correct?

db.table.find({groupA: data} || {groupB: data}, function(err, records)
like image 814
Jim Chen Avatar asked Nov 24 '14 23:11

Jim Chen


2 Answers

Make use of the $or operator.

db.table.find({$or:[{"groupA":data},{"groupB":data}]}, function(err,data){
})
like image 188
BatScream Avatar answered Sep 20 '22 19:09

BatScream


Use the $or operator in your query:

 db.table.find({$or:[{"groupA": data}, {"groupB": data}]}, 
     function(err, records){
      //code to be executed.
     });
like image 34
Praveen Avatar answered Sep 19 '22 19:09

Praveen