ca1c
ca1c

Reputation: 1285

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

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.

Upvotes: 0

Views: 369

Answers (1)

Anveeg Sinha
Anveeg Sinha

Reputation: 505

$or documentation

Basic syntax -

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

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

Upvotes: 1

Related Questions