Forrest logo
back to the mongo tool

mongo:collections:show

Display all MongoDB collections in the current database.
$ mongo --quiet --eval 'db.getCollectionNames().forEach(printjson);'
try on your machine

The command mongo --quiet --eval 'db.getCollectionNames().forEach(printjson);' is used to connect to a MongoDB database using the MongoDB shell and print the names of all collections in the database.

Here's what each part of the command does:

  • mongo: This command starts the MongoDB shell and connects to the default MongoDB instance running on the local machine. It's the command-line interface for interacting with MongoDB.

  • --quiet: This option suppresses the output of non-error messages. It prevents MongoDB from printing additional information and only displays the required output.

  • --eval 'db.getCollectionNames().forEach(printjson);': This option specifies the JavaScript code that should be executed in the MongoDB shell. The code db.getCollectionNames() returns an array of all collection names in the current database. The forEach function is used to iterate over each collection name, and printjson is a function that prints each collection name in JSON format.

In summary, this command connects to a MongoDB database, retrieves the names of all collections, and prints them in JSON format.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the mongo tool