Cannot get output from db.movies.find({mpaaRating:"PG-13"}).pretty() while following video lesson

The title pretty much sums it up. Here are my last several commands in the shell. As you can see, the only output I get is when it switches the db to movies, 100YWeatherSmall, etc…
copy paste of cmd commands and outputs:

MongoDB Enterprise Cluster0-shard-0:PRIMARY> show collections
MongoDB Enterprise Cluster0-shard-0:PRIMARY> use movies
switched to db movies
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show collections
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.find({mpaaRating:“PG-13”}).pretty()
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

It should show collections.Are you able to see collections under other DB’s?
MongoDB Enterprise Cluster0-shard-0:PRIMARY> use video
switched to db video
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show collections
movies
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.find({“mpaaRating”:“R”}).count()
17657

2 Likes

@Filip_48750 Couple things to check

  1. Make sure you’re connected to the right cluster/node. There is the Class cluster and the Atlas Cluster

  2. Is there any output in the mongod log showing an error associated to the command you entered?

HTH,
Mike

1 Like

Here is a copy paste of my command prompt:
C:\src\m001\loadMovieDetailsDataset>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/test?replicaSet=Cluster0-shard-0” --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics
MongoDB shell version v4.0.5
connecting to: 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/test?authSource=admin&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0
2019-01-20T09:10:59.115+0100 I NETWORK [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017
2019-01-20T09:10:59.714+0100 I NETWORK [js] Successfully connected to cluster0-shard-00-01-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-01-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-01-20T09:10:59.714+0100 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to cluster0-shard-00-02-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-02-jxeqq.mongodb.net:27017 with a 5 second timeout)
2019-01-20T09:11:00.452+0100 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to cluster0-shard-00-00-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-00-jxeqq.mongodb.net:27017 with a 5 second timeout)
Implicit session: session { “id” : UUID(“d8f96dd9-b424-4387-ba6d-e6a9362ac132”) }
MongoDB server version: 3.6.9
WARNING: shell and server versions do not match
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show collections

As you can see show collections leaves empty output, even though I am doing everything as was done in lesson 2.3 - connecting to Class Atlas Cluster from the mongo Shell

May be shell version differences
From forums:
“For MongoDB 3.0 deployments using the WiredTiger storage engine, if you run db.getCollectionNames() and db.collection.getIndexes() from a version of the mongo shell before 3.0 or a version of the driver prior to 3.0 compatible version, db.getCollectionNames() and db.collection.getIndexes() will return no data, even if there are existing collections and indexes. For more information, see WiredTiger and Driver Version Compatibility.”

1 Like

So, from your connection string, you’re connecting to the “test” database by default, it may have no collections. The version mismatch is likely not causing any issues in this context.

After you login, type “show dbs”, and make sure that you’re in the database you want to be (i.e. the “movies” database)

HTH,
Mike

1 Like

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/video?replicaSet=Cluster0-shard-0

In the lecture videos, they mention that in the connection string you can change the “test” database to one that exists, like “video”.

Also, there is no “movies” database, it’s a collection in the “video” database.

Once, you connect to course database, type the following:
> show dbs

A list of database names is displayed:

100YWeatherSmall  0.128GB
admin             0.000GB
aggregations      0.067GB
citibike          0.367GB
city              0.002GB
config            0.000GB
coursera-agg      0.083GB
local             1.089GB
mflix             0.288GB
results           0.000GB
ships             0.001GB
video             0.470GB

Then switch to the “video” database which has a collection called “movies”.

> use video
switched to db video
> show collections
movies

Thank you, I truly was connecting to the wrong database.

I am getting exactly what you have shown up to use video. But when trying to get the collections, it isn’t showing anything.

MongoDB Enterprise Cluster0-shard-0:PRIMARY> show dbs
100YWeatherSmall 0.117GB
admin 0.000GB
aggregations 0.067GB
citibike 0.361GB
city 0.002GB
config 0.000GB
coursera-agg 0.083GB
local 0.881GB
mflix 0.458GB
results 0.000GB
ships 0.001GB
video 0.448GB
MongoDB Enterprise Cluster0-shard-0:PRIMARY> use vedio
switched to db vedio
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show collections
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show collections
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

There is a typo in your use db command
It should be video not vedio

1 Like

I am using my Sandbox database when I try doing the find method I get nothing returned. Connecting to the same database via compass I get results so I am pretty sure I am connecting to the correct database

HI @Douglas_L_Larson_12657,

I believe the find() query that you are issuing is not on the correct collection or the condition in the query must not be matching any document. I would recommend you to execute the following commands and share the results.

To list all the databases

show dbs

To find out the database to which your db variable is pointing to.

db

To list all the collections present in your current database

show collections

Finally, I would request you to share the find() query which are issuing on your database.

Thanks,
Shubham Ranjan
Curriculum Support Engineer