Reputation: 6926
transporters.count({ '$and': [ {} ] })
transporters.count({ })
Is it the same?
Is it possible the empty object cause speed issues?
Upvotes: 1
Views: 89
Reputation: 13795
Yes both queries are considered the same.
This can be seen in the explain output of both queries:
> db.test.explain().count({})
{
"queryPlanner": {
"plannerVersion": 1,
"namespace": "test.test",
"indexFilterSet": false,
"winningPlan": {
"stage": "COUNT"
},
"rejectedPlans": [ ]
},
....
and:
> db.test.explain().count({$and:[{}]})
{
"queryPlanner": {
"plannerVersion": 1,
"namespace": "test.test",
"indexFilterSet": false,
"winningPlan": {
"stage": "COUNT"
},
"rejectedPlans": [ ]
},
....
The explain()
output of both queries are identical, meaning both queries will execute the same way.
Upvotes: 1