Heether
Heether

Reputation: 160

What is the difference between the 2 Mongo queries below

Db.test.find({field1: true, field2: true})

Db.test.find({$and:[{field1: true},{field2:true}]})

I fired a count on both these queries and the count was same Help appreciated

Upvotes: 1

Views: 26

Answers (1)

Jerod Johnson
Jerod Johnson

Reputation: 784

Those two queries are effectively the same.

According to the MongoDB 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.

source: https://docs.mongodb.com/manual/reference/operator/query/and/

Upvotes: 3

Related Questions