Which one is faster $all or $and when used in the query explained in the below message?

Hi, I used the query something like this :
{ $and: [{“sections”: “AG1”},{“sections”: “MD1”},{“sections” : “OA1”}] }, which gave me all the records matching the above query. While learning $all for Array values, if I query something like this, {sections: {$all: [“AG1”, “MD1”, “OA1”]}}, It still gives me same result count.

My question is, Are both the queries fine to use from the perspective of faster retrieval. Which one among these two is more efficient to use ?? I guess $all should be more efficient but I want to conform from you guys.

Hi @Omkar_40282,

Good question!

Here’s a screenshot from the $all documentation:

Now, when the Query Planner evaluates the query, it will re-translate $all to $and. Therefore, from an execution performance point of view, they both will yield the same performance stats.

1 Like

Ohh…Thanks alot :blush:

:slightly_smiling_face: :+1:

1 Like

Thanks @007_jb.

Hi @Omkar_40282,

For detailed explanation, you can refer this post as well.

Please feel free to get back to us if you have any other query.

Shubham Ranjan
Curriculum Services Engineer