Home > Blockchain >  Find all documents that match with at least one of query criteria given
Find all documents that match with at least one of query criteria given

Time:04-05

So I want to be able to find a document in my mongo database that matches with at least one of the multiple criteria given. I am not sure how to do this but I guess I can explain it with this incorrect syntax:

User.find({ username: username } || {email: email});

I looked in the mongoose documentation and I couldn't find anything on this. (I may have overlooked something) but if someone can point me towards the correct code that would be great.

I am trying to replace the method of using multiple function calls.

CodePudding user response:

$or documentation

Basic syntax -

{ $or: [ { < expression1> }, { < expression2> }, ... , { < expressionN> } ] }

 User.find( { $or: [ { username: username }, {email: email} ] } )
  • Related