MongoDB Basic Command and noSql Query

MongoDB Basic Command and Installation

MongoDB is document based NoSql Database written in C++.

Before Learning MongoDB we must have the basic idea of SQL vs NoSqL.

Difference Between SQL and NOSQL




SQL(Structured Query Language)
  • SQL database is primarily known as RDBMS (Relational Database Management System) which is table based Database. Data is Stored in Table.
  • SQL database is vertically Scalable. Oracle, Postgres, MsSql etc is example of RDBMS.
NOSQL
  • NOSQL database is primarily known as Non Relational Database or distributed Database which store the data in the form of document or key value pair etc.
  • NOSQL is Horizontally scalable, MongoDB, Redis, NEO4J is NOSQL Database Example. 

Before Using MongoDB You must know the basic command to run, View and execute the query on command prompt. First Install the MONGODB Server.


  • Command to run the MongoDB Server
                 ➥ mongod  (Type this Command and press Enter)

  • To Check the Version of MongoDB Installed 
                 ➥ mongo --version  (Type this Command and press Enter)

  • To Start the MongoDB Type the Command in Cmd Prompt
                  mongo  (Type this Command and press Enter)

  • Command to Create DB in Mongo
                 ➥ use db-name  (db-name can be anything Type this Command and press Enter)

  • To Check the Status of Created Database In MongoDB
                 ➥ show dbs  ( Type this Command and press Enter)

Note : Once we use the above command to know the status of Database creation. Our newly created database will not come in the list because it do not contain any collection.

So Once you create the Database in MongoDB create few collection in that then by using   show dbs command you can see the DB created by you in the list. Once you create the collection you can view the list of Database.
  • To use particular DB from the list use this command, by default test DB is used.
                  ➥ use db-name  ( Type this Command and press Enter)

  • Command to know the current DB which is used

                  ➥ db  ( Type this Command and press Enter)


How to create the collection in MongoDB

  • Command to Create the collection in MongoDB

                    ➥ db.createCollection("  Collection-Name ")  ( Type this Command and press Enter)


  • Command to Show all the collection Created In Mongo Database

                    ➥ show collections  ( Type this Command and press Enter)


  • How to Drop the collection From The MongoDB

                    ➥ db.collection-name.drop()  ( Type this Command and press Enter)


  • How to Drop any Database created in MongoDB

                     ➥ db.dropDatabase()  ( Type this Command and press Enter)


No comments:

Post a Comment

Our Feature Post

There is a tree between houses of A and B If the tree leans on As House

    There is a tree between houses of A and B. If the tree There is a tree between houses of A and B. If the tree leans on A’s House, the t...

Our Popular Post