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.
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
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
@Joe_McNeil , what are you trying to do?
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
In the MongoDB shell:
show dbswill show all databases
use <db>will select a database (
<db>is a placeholder for a database name)
dbwill confirm the current database name
show collectionswill show you all collections in the currently selected database
db.movies.find()will find documents in the
moviescollection in the current database
db.users.find()will find documents in the
userscollection 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.
The “collection” in
db.collection.find() should be a specific name of collection