Mongo Shell

  1. It is a component of MongoDB
  2. Shell provides an interactive javascript interface.
  3. The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mongo shell to query and update data as well as perform administrative operations.
  4. In windows to use mongo shell find mongo.exe and run it.
  5. To start or work on the shell you need to start mongod.exe which is present on installation path of C:\Program Files\MongoDB\Server\4.0\bin
Mongo Shell
  1. Crud operation is perform using mongo shell and also it provides support for JavaScript. It means you can use JavaScript functions or JavaScript code for that.

Mongodb shell commands you can found on this link

Command Helpers

Mongo Shell
Mongo Shell

Commands Explain

Help to get help and show commands on the console

Mongo Shell

Shortcut to clear mongo screen ctrl + l

  1. List of databases: show DBS
Mongo Shell

Show the collections in databases use: Show collections

If your DB is not selected then it showing blank for that you can first select the database by using this command Use database databasename / use database name to select the database.

Mongo Shell

Use DatabaseName:- this command is used to switch the database if already present else it will create the database for you. But when you used show DBS command after that it will not show the newly created database. For this purpose, we have to add collection into that newly created database.

  1. JavaScript equivalent command for getting collection names of current database is db.getCollectionNames()
  2. Default collection created by mongodb is system.Indexes.
  3. You can create javascript functions using the mongo shell and called by using function name.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *