How do I perform an OR operation query in nodejs / MongoDB?

I'm trying to query mine mongodb

, but I don't know which line my data is on, so I'm trying to query both lines with parameters, is this syntax correct?

db.table.find({groupA: data} || {groupB: data}, function(err, records)

      

+3


source to share


2 answers


Use the $ or operator .



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

      

+5


source


Use the $ operator or ( http://docs.mongodb.org/manual/reference/operator/query/or/):-



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

      

+3


source







All Articles