I am currently a bootcamp student and have created 2 collections with 10 documents in 1 and 3 documents in another but db.collections.find() only works sometimes it doesn’t always work more often than not it doesn’t and I’m using Mac anyone else having this kind of trouble??

Can you post your code, including the code used to create your collections and provision them with documents? Your question amounts to the classic “it doesn’t work” and is unanswerable as posed.

i can post a github link otherwise i can only post on picture due to me being new to the community.

here is the terminal in which i tried to do the db.collection.find()

it seems to be mostly an issue with the terminal side of it. i created a database in the terminal and created 2 collection called movies and users. the users collection should have 4 documents and the movies should have 10 sometimes i can get it to show but most times it does not.

Well, the first thing is you’re already connected to the localhost after issuing the mongosh command. I see you trying to connect after you’re already connected.

Db.collection.find() is not correct
You have to replace collection with your collection name
Check your collections under mflix db
Show collections

As Jack_Woehr mentioned you are trying to start another mongod while already connected to a mongod

Yeah I have I’m just saying this as an example

So before this instance I had tried it prior as well without running the instance

I’ve lost track of this discussion :slight_smile:
@Joe_McNeil , what are you trying to do?

I am using mongodb from my MacBook. I created a database named myFlixDB with 2 collections. Movies and users. For no apparent reason using the db.movies.find() or db.users.find() now shows that they databases are empty. I had 10 documents in the movies collection and 4-5 documents in the users collection. I had to submit them via a screenshot showing the data 2 weeks ago so I know they have data in them but now they show empty. I’m not worried about any of my JavaScript or node.js that’s not the issue I am having. Given that I cannot show any of the data I cannot export it and then cannot import it to mongo atlas.

Just diagnosing this by telepathy, my guess is you added the collections to the wrong db and are looking in the wrong place.


Welcome to the MongoDB Community @Joe_McNeil!

As mentioned in earlier comments, you need to specify collection names when using db.<collection>.find(). Your example query will only work if you have a collection called collections.

In the MongoDB shell:

  • show dbs will show all databases

  • use <db> will select a database (<db> is a placeholder for a database name)

  • db will confirm the current database name

  • show collections will show you all collections in the currently selected database

  • db.movies.find() will find documents in the movies collection in the current database

  • db.users.find() will find documents in the users collection in the current database

I suggest giving MongoDB Compass a try as an administrative GUI. Compass has handy features for interacting with data in a MongoDB deployment and also embeds the MongoDB shell so you still have the option of using a command line interface.


1 Like

The “collection” in db.collection.find() should be a specific name of collection