Mongo DB – Basic commands

By | 17/11/2021

In this post, we will see some MongoDB basic commands that will help us to manage our MongoDB instances.
Here, we can find all Mongo DB’s commands.


First of all, we connect to Mongo shell with the command mongo and then, we will start to run some commands:

SHOW DBS – It shows all databases

USE “database name” – It selects or create a new DB

DB – It shows the current selected database

DB.CREATECOLLECTION(“collection_name”) – It creates a new collection in the selected db

It is interesting know that until we don’t insert a collection in a new database, the database will not visible when we run the command show dbs.
For example, if we use a new db called test2db and then we run the command show dbs, this will be the result:

Now, if we create a collection called Test and then we run show dbs again, this will be the result:

SHOW COLLECTIONS – It shows all current database ‘s collections

DB.”collection_name”.INSERT() – It inserts one document in a collection

DB.”collection_name”.INSERTMANY() – It inserts many documents in a collection

DB.”collection_name”.FIND() – It shows the documents list

DB.”collection_name”.REMOVE(‘criteria’) – It deletes one or more documents

DB.”collection_name”.DROP() – It deletes a collection

DB.DROPDATABASE() – It deletes the selected database



Leave a Reply

Your email address will not be published.