Queries for the MongoDB Array search

What is the difference between the below two queries-

  1. db.movieDetails.find({“genres”:“Family”}).count()
    result 8
  2. db.movieDetails.find({“genres”:[“Family”]}).count()
    result is 124

Hi ritesh_12318,

Your queries seemed jumbled, it must be this way:

 db.movieDetails.find({“genres”:[“Family”]}).count()

This query matches the exact array with only one element and with value: “Family”. If you will look into those 8 records, you will be able to see that.

And the second query below one, matches for “Family” element in genres array and it does not matter whether it is the only element.

db.movieDetails.find({“genres”:“Family”}).count()

Let me know if that helps.

Kanika

Thanks Kanika, it does help to get the concept and clear my confusion. once again many thanks. :slight_smile: