Skip to main content

MongoDB $and and $or Operators

MongoDb OR ($or) Operator

The $or operator are used to performs a logical OR operation on more than two expressions and returns all the match documents.

Syntax:  {$or: [ { <expression 1> }, { <expression 2> }, .. , { <expression N> } ]}

Query:
db.customers.find({
       "$or": [{ "Age": 30 },
 { "Name": "Anil Singh" }]
});

MongoDb OR ($or) AND AND ($and) Operator

The $and operator are used to performs a logical AND operation on more than two expressions and returns all the match documents.

Syntax:  {$and: [ { <expression 1> }, { <expression 2> } , .. , { <expression N> } ] }

Query:

db.customers.find({
              $and:[
                        {$or:[{"Name" : "Anil Singh"}
                  ]},
                  {"Age": "30"}
]});