Lab 2.4: Queries on Array Fields, Part 1

In compass, i ran these query and got following output. Can anyone explain why?
{‘genres.0’:‘Comedy’} - Result : 494
{‘genres’:[‘Comedy’]} - Result : 165

Use double quote -> “genres.0”: “Comedy”

{‘genres.0’:‘Comedy’} - Result : 494

This finds all movies whose first genre is “Comedy”. It includes movies which have only one genre (“Comedy”) as well as movies with more than one genre (e.g. first genre “Comedy” and second genre “Documentary”).

{‘genres’:[‘Comedy’]} - Result : 165

This finds all movies whose unique genre is “Comedy”. It is a subset of the first result which is why there are fewer matches.

For example, the following document is matched by the first query but not the second one:

2 Likes

Lovely… thanks a lot explaining in depth.

Double quotes and single quotes should not matter. They both work in same manner.