Query doesn't return any result

Just finished Lecture - Reading Documents: Array Fields while trying to complete quiz I wrote a command on CLI which doesn’t produce any result
2019-07-09_14-06-18
Please note that mogdodb shell version is 4.0.10

Hi @Shayan.K,

As I can see in the screenshot, you are issuing the query on the wrong database.

The name of the database is video and inside this database we have the movieDetails collection. So the right way to issue the query is :

use video

Now the db variable points to the video database. You can verify this by typing db in shell and hit enter. You can also view the list of the collections available in this database by issuing the query :

show collections

Now you can query your movieDetails collection.

Thanks,
Shubham Ranjan
Curriculum Support Engineer

3 Likes

Hey @Shayan.K

Looking at your terminal output it appears you first switched to the video db.
Then it looks like you switched to(and created) a database named movieDetails; which does not exist.

Therefore I think you would want to connect to the video db, then search the movieDetails collection in that db with your query to find The Big Lebowski.

# Connect to the mongo shell
mongo "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/aggregations?replicaSet=Cluster0-shard-0" --authenticationDatabase admin -u m001-student -p m001-mongodb-basics --ssl --norc
#Inside the mongo shell switch to mflix database
use video
# search the movieDetails collection
db.movieDetails.find({writers: ["Ethan Coen", "Joel Coen"]}).pretty()

When you first connect to the shell you can run the following to see the databases in the cluster

show dbs

And once you have selected a db with use video you can you the following to see all the available collection in that database

show collections
1 Like

@Shubham_13709

Hey I just was reading over your answer and wanted to inquire about a movieDetails collection on the video db. The only collection I have listed under video db is movies. Which reflected in my answer to @Shayan.K about using the mflix db, which has the movieDetails collection.
Maybe I am not connected to the correct cluster? I just want to make sure so that I do not lead anyone astray with incorrect information.
:smile:

1 Like

Thanks @Shubham_13709 but I just want to ask another question which comes in my mind that why it doesn’t generate error when I command use moviDetails as it is a collection not db instead it shows

switch to db movieDetails as shown in snapshot

@Shayan.K
Mongodb is very easy going and when you type use movieDetails it creates a new database in memory, and will save it if/once new documents are added.
If you were to type show collections after use movieDetails you would see that there are no collections in the database.

2 Likes

Hi @natac13,

In the M001 course, we have created a sandbox cluster and has imported the loadMovieDetailsDataset.zip into it.

For further information refer the lecture videos.

Thanks,
Shubham Ranjan
Curriculum Support Engineer

2 Likes

@Shubham_13709
Thank you. I completely forgot about that step in the course. Will update my answer accordingly.