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:
Basic syntax -
{ $or: [ { < expression1> }, { < expression2> }, ... , { < expressionN> } ] }
User.find( { $or: [ { username: username }, {email: email} ] } )