Introduction to MongoDB Basic Commands

View Databases

 
show databases

Switch to a Database

 
use vitdb

View all collections

 
show collections

Add collection to the database

 
db.createCollection("courses"); 

Drop a collection (db.collectioname.drop)

 
db.courses.drop() 

Drop Database

 
db.dropDatabase()

Insert a Document

 
db.employee.insert({"name":"Jeff"})

View the Documents in a Collection

 
db.employee.find()

Insert Many Documents into a collection

 
db.employee.insertMany([ {"name":"first"},{"name":"second"}])

Delete one record into a Collection

 
db.school.deleteOne({"name":"sbst"})

Delete all records in a Collection

 
db.employee.deleteMany({})

Delete many records matching a criteria

 
db.school.deleteMany({"name":"smv"})