Queries for documents always returns "null"

Hi, I’m not sure what I’m doing wrong. This kept happening on IDE, so I switched to installed and switched to mongo Compass. I’m creating a successful connection, I can show dbs and see all training library, use a db, show collections, use a collection. But I can never get it to query a result. I’ve got admin permissions on this test server and have completed some tests since I am doing the proper code but it’s jsut not returning any documents ever. I can insert and delete fine. I can also find all the documents on the Atlas without any issue. Here is an example screenshot of the simple db.zips.findOne() queries I’m trying that bring null responses

Are you sure there was data to be returned?

How about running that same findOne after the insertOne?

Asya

1 Like

I think you are connected to wrong DB
Your prompt shows zips
Looks like you switched to zips
zips is a collection not DB
Before running any query you can do this
db----->will show which db you are connected
show collections

3 Likes

Thank you – For anyone having the same trouble

I’ve been going

  1. show dbs
  2. use sample_training
  3. show collections
  4. use zips
  5. db.zips.findOne()

Which doesn’t make sense and was instead creating a database called zips. “use” command is only on a DB level afaik. I’m new to this. Hopefully this is helpful for someone and makes sense.

instead you should simply use sample_training then do db.zips.findOne()

thank you for the help.

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.