Mongo Shell incorrect query result

I’m trying to use the same filters on Mongodb shell but getting incorrect result. Using compass has no issues.

db.video.movieDetails.find({genres: “Comedy”}).count()
0

what am I missing here?

Please check your syntax
db.video.movieDetails.find

there was no syntax error. But I figured it works when I do not use the DB name, not sure why. Appreciate if someone can explain.

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

Hi @Om_Prakash_58464

The ‘use’ command in the MongoDB shell sets the database context or more plainly the specific database you wish to use. This helper method then allows you issue commands against ‘db’ where this is the database context/specific database. It’s really just a helper method to help you set the current database you wish to use.

Hope this helps!
Eoin

1 Like

Hi,
It does help clear the confusion I had. Thank you!

1 Like