Db.movies.find({genre: “Action, Adventure”}, {title: 1}) not working

The below command is not giving any results. Connected to Atlas Sandbox Cluster. Please see the attached screenshot.

db.movies.find({genre: “Action, Adventure”}, {title: 1})

image

I suspect the quotes. Use normal double quotes. Normal single quotes might also work.

Hi @Priyanka_79580,

In addition to @steevej-1495,

video.movies collection is present in the class atlas cluster and not in your sandbox cluster. Please make sure that you are connected to the right cluster.

~ Shubham

I don’t know if you have already figured it out, but all find criteria should be in one {}. So try db.movies.find({“genre”: “Action, Adventure”, “title”:1}).pretty(). If gives me nothing if that’s what you intended.

Wrong recommendation from @Kyutae_08919. There is a big difference between

and

Refer to documentation at https://docs.mongodb.com/manual/reference/method/db.collection.find/ to see the difference.

For short, the first is find( predicate , projection ) and the other is find( predicate ). In the first case you look for a genre and you project the title. In the second case you are looking for genre and a title equals to 1 and you output the whole document.

1 Like

Hi @Kyutae_08919,

I hope you found @steevej-1495’s response helpful. Please let us know if you have any doubts/confusions.

~ Shubham

how to connect to class atlas cluster?

Hi @Atul_Kumar,

The connection string for class Atlas cluster is given in this lecture. Please take a look at this lecture Chapter 0: Connecting to Our Class Atlas Cluster from the mongo Shell.

Connection string :

mongo "mongodb+srv://cluster0-jxeqq.mongodb.net/test" --username m001-student --password m001-mongodb-basics

~ Shubham