Thanwa Ch.
Thanwa Ch.

Reputation: 135

Difference between projection multiple fields and use $and operation

How difference between

db.collection.find({ field1: <value>, field2: <value> })

and

db.collection.find({ $and: [{field1: <value>}, {field2: <value>}] })

Upvotes: 0

Views: 199

Answers (1)

Israel Zinc
Israel Zinc

Reputation: 2769

There's no difference. From the documentation:

MongoDB provides an implicit AND operation when specifying a comma separated list of expressions. Using an explicit AND with the $and operator is necessary when the same field or operator has to be specified in multiple expressions.

Hope my answer was helpful.

Upvotes: 2

Related Questions