newbie
newbie

Reputation: 103

Does MongoDB simplify query logic?

Are the following logical equivalent queries handled by the server differently?

{"Name":"1"}

{$and:[{"Name":"1"},{$or:[{"Name":"1"},{"Tag":"a"}]}]}

Since the second query include the "Tag" field, does it affect index usage?

Upvotes: 1

Views: 290

Answers (1)

J. Carlos Calvo
J. Carlos Calvo

Reputation: 21

If you want to experiment and see what mongo is doing for each query you can use an explainable object in the mongo shell.

I cannot answer your question since you do not provide information about the indexes defined in your database, but using this you can see it by yourself in the "queryPlanner" section. If it's using an index it shows "IXSCAN" at "stage" field.

Upvotes: 1

Related Questions