Basic Shell Commands
MongoDB Shell, has always been the quickest way to connect, configure, query, and work with your MongoDB database. It acts as a command-line client of the MongoDB server. However, there is now a new GUI version of the MongoDB Shell called MongoDBCompass that may be more intuitive for some. This is installed when you install MongoDB.
You can start MongoDB Shell by executing [mongo] command, (on older versions), or [mongosh] command, (on newer versions), on the command prompt/terminal. mongosh is the new MongoDB shell with some more features than the old mongo shell.
- Type [help] to display all the commands which you can use with mongo or mongosh.
There is a good list of the shell commands at TutorialsTeacher.com, but here are a few of the basics:
| Command | Use |
| mongosh | start the mongoDB shell. |
| version | displays the current shell version. |
| help | display the list of basic commands. |
| cls | clears the current screen. |
| show dbs | displays a list of available databases. |
| show collections | displays a list of collections in the current database. |
| exit/quit/ctrl+c | quit the mongoDB shell. |