Jupyter Notebook collection movies well connected but empty

Hello everyone, I’m working with your_first_read jupyter notebook. I connected successfully to the db on my Atlas server, but when I try to get documents from movies collection it says it has 0 documents. Also when I execute movies.find_one() the result is None.

These are the results when I print variables client, m220 and movies:

client:
MongoClient(host=[‘cluster0-shard-00-00-b.mongodb.net:27017’, ‘cluster0-shard-00-02-b.mongodb.net:27017’, ‘cluster0-shard-00-01-b.mongodb.net:27017’], document_class=dict, tz_aware=False, connect=True, authsource=‘admin’, replicaset=‘Cluster0-shard-0’, ssl=True)

m220:
Database(MongoClient(host=[‘cluster0-shard-00-00-b.mongodb.net:27017’, ‘cluster0-shard-00-02-b.mongodb.net:27017’, ‘cluster0-shard-00-01-b.mongodb.net:27017’], document_class=dict, tz_aware=False, connect=True, authsource=‘admin’, replicaset=‘Cluster0-shard-0’, ssl=True), ‘m220’)

movies:
Collection(Database(MongoClient(host=[‘cluster0-shard-00-00-b.mongodb.net:27017’, ‘cluster0-shard-00-02-b.mongodb.net:27017’, ‘cluster0-shard-00-01-b.mongodb.net:27017’], document_class=dict, tz_aware=False, connect=True, authsource=‘admin’, replicaset=‘Cluster0-shard-0’, ssl=True), ‘m220’), ‘movies’)

When I execute movies.count_documents({}) I get 0.

This is a screenshot from my Atlas cluster…

Screenshot%20from%202018-10-27%2011-20-39

Do you have any ideas why I cannot access to the documents of movies?

Hi Leticia,

By default the Notebook has “m220” as the database for our client which does not exist in out MongoDB Database. To solve this, you may either create a database using Compass or Atlas named as “m220” or you may just change the database name to an existing database name.

1 Like

Thank you for your response! I made a mistake: the db’s name on my Atlas cluster is mflix not m220, but as I just executed the code I didn’t pay attention to this. What I did was to list all the data bases from the connected client:

dbs = client.list_databases()
for db in dbs:
    print(db)

And that showed me:

{'name': 'mflix', 'sizeOnDisk': 184705024.0, 'empty': False}
{'name': 'admin', 'sizeOnDisk': 196608.0, 'empty': False}
{'name': 'local', 'sizeOnDisk': 3048931328.0, 'empty': False}

I changed the db’s name on my code and everything is working correctly.

3 Likes

Great! I actually misread your “first-read” as “first-write” that’s why I was talking about “electronicsDB”. Great that you’ve solved it yourself! :smiley: