• MongoDB is an open-source database.
  • MongoDB is work on concept document and collection.
    • Document: It is a set of key-pair values. For example, We create Student Database we store data {Roll Number, Name, Score} this information of each student called document of each student.
    • Collection: Collection in MongoDB is collection of documents. For Example Number of the student in the class so the combination of all students is Collection.
  • MongoDB is using a document to store data in database instead of Row and Column in Mysql.
  • It is a NoSQL database. It is faster than the SQL query database.
  • MongoDB provides users with an unstructured type database.

Commands for MongoDB

This section exaplain the most common used of command of MongoDB.Commands are insert,delete,update,search with example.

Database > Collection -> Document

use <databasename>

  1. This command use to mainly create database,if we use this command “use school” it will create database name school .If school type database already present then it will switch to school database. For example:
  2. Here we can create a database name school in MongoDB.

show dbs

This Command will show all the database name in the Mongo Database.If you Created new database but not created any document in the that class then it will not show that database,it show only those database name those will contain some collection and document. For Example:

Here it will show the all database name .


This Command used to create a collection in the database. Run this command in the database then it will create a new collection.For Example:

Here we use to create collection name classfive in our database. When run this command it show Create or not “ok” : 1 -> Successfully Created “ok” : 0 -> Failed .


This command used to delete collection from database. Here We drop the class name “classfive” from database .For Example:

After Run this command if it show true “Successfully Drop” , false “Failed”.


This command use to insert document in the collection.So Here we insert the document in the collection “class”. For Example:

After Running this command it give output WriteResult ({“nInserted”:1}) ,its means insert successfully. If you want to insert multiple document in the collection. For Example :

Here we insert Multiple document in the collection “class” at a time .


This command use to show the all the document in the collection.So here we run command to show document of the collection “class”.For example:

Here it will show the all document of the collection “class”.


This command used to show the first document of the collection.So here we run command to show the first document of the collection “class” .For Example :

db.collectionname.find({name: value})

This command used to find specific document from the class by given parameter name and parameter value.So here we run this command to find document from the collection whose “Roll Number ” is 1 . For Example:


This command used to show the document in pretty order.So we want to show our collection data in specific order thats look good .For example :

For More details Mongodb Tutorials.

For More Related topics …

%d bloggers like this: