Jim Chen
Jim Chen

Reputation: 167

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)

Upvotes: 9

Views: 13440

Answers (2)

Praveen
Praveen

Reputation: 113

Use the $or operator in your query:

 db.table.find({$or:[{"groupA": data}, {"groupB": data}]}, 
     function(err, records){
      //code to be executed.
     });

Upvotes: 4

BatScream
BatScream

Reputation: 19700

Make use of the $or operator.

db.table.find({$or:[{"groupA":data},{"groupB":data}]}, function(err,data){
})

Upvotes: 17

Related Questions