1
transporters.count({ '$and': [ {} ] })

transporters.count({ })

Is it the same?

Is it possible the empty object cause speed issues?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.