Friday, June 2, 2017

Mongo db Install

💥 How to install Mongodb

      💢 Start MongoDB


                     👀 sudo service mongodb start

       💢 Stop MongoDB


                    👀 sudo service mongodb stop

          💢 Restart MongoDB


                     👀 sudo service mongodb restart
 
  💥 To use MongoDB run the following command.


                       👀 mongo
 
 
  💥How to create database

            💧If you want to create a database with name <mydb>, then use database statement would be as follows 


>use mydb
switched to db mydb
 
           💧To check your currently selected database, use the command db


>db
mydb
 
            💧If you want to check your databases list, use the command show dbs.


>show dbs
local     0.78125GB
test      0.23012GB
 
           💧Your created database (mydb) is not present in list. To display database, you need to insert at least one document into it.


>db.student.insert({"name":"Abi"})
>show dbs
local      0.78125GB
mydb       0.23012GB
test       0.23012GB
 
      
  💥 How to drop Database
 
 
Basic syntax of dropDatabase() command is as follows −
💥db.dropDatabase() 

          💧This will delete the selected database. If you have not selected any database, then it will delete default 'test' database.


     👉First, check the list of available databases by using the command, show dbs.

      💧>show dbs
 local 0.78125GB 
mydb 0.23012GB 
 test 0.23012GB 
 
      👉If you want to delete new database <mydb>, then dropDatabase() command would be as follows 

    💧>use mydb switched to db mydb  
     > db.dropDatabase() 
     >{ "dropped" : "mydb", "ok" : 1 } >
 
       👉Now check list of databases.

>show dbs 
 local 0.78125GB 
test 0.23012GB >

No comments:

Post a Comment