Is it possible to show all collections and its contents in MongoDB?
Is the only way to show one by one?
To get stats about MongoDB server, type the command db. stats() in MongoDB client. This will show the database name, number of collection and documents in the database.
Fetch all data from the collection If we want to fetch all documents from the collection the following mongodb command can be used : >db. userdetails. find(); or >db.
In MongoDB, you can use the show dbs command to list all databases on a MongoDB server. This will show you the database name, as well as the size of the database in gigabytes.
Find() Method. In MongoDB, find() method is used to select documents in a collection and return a cursor to the selected documents.
Once you are in terminal/command line, access the database/collection you want to use as follows:
show dbs use <db name> show collections
choose your collection and type the following to see all contents of that collection:
db.collectionName.find()
More info here on the MongoDB Quick Reference Guide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With