Atlas cluster shows data for the training academy db, however , Mongo shell returns zero count for all collections

Hi,
I am facing issues where in Atlas cluster shows data for the training academy db, however , Mongo shell returns zero count for all collections.

Thanks

Hi @priyesh_srivastava,

Can you kindly share the screenshot of the command and the error msg of your shell/IDE.?

Regards,
Kushagra

HI Keshav,
Please see the screenshots from Atlas and the shell. While Atlas shows data, shell shows zero count.

Thanks,
Priyesh

@Kushagra_Kesav, please see the attached images.

Hi @priyesh_srivastava,

Based off your screenshot, you have performed use sample_training to switch to the sample_training database. You then list the collections within the sample_training database using show collections. These commands are both fine for wanting to view your database(s) and collection(s).

However, you then perform the command use trips which switches you to database trips. When you ran the show dbs at the start, you can see a list of all databases containing data. Within the list, there isn’t a database named trips. This is why you are seeing a count of 0 when performing db.trips.find().count() within the trips database.

In short, the use <db> command should be used when you want to utilise / switch to a particular database, not for switching to a collection name.

Database = sample_training
Collection = trips

Correct me if I am wrong in my assumption, but it seems you are trying to perform a count on the trips collection which is contained in the sample_training database. To do this, you will need to switch to the sample_training database first by running use sample_training and then run the db.trips.find().count() command. You do not have to run use trips.

Please see the example below on my own test instance which may be of help:

Hope this helps.
Jason

4 Likes