Professional Documents
Culture Documents
This list covers almost all the most used commands in MongoDB.
Let assume that you are working inside a collection named ' EmpDetail ' on a
MongoDB database of your choice
1. Database Commands
show dbs
use dbEmployee
db
Delete Database
db.dropDatabase()
2. Collection Commands
Show Collections
show collections
db. EmpDetail.drop()
3. Row(Document) Commands
db. EmpDetail.find()
db. EmpDetail.find().pretty()
db. EmpDetail.insert({
'name': pooja,
'lang': c,
'member_since': 4
})
db. EmpDetail.insertMany([{
'name': ‘Drashti’,
'lang': 'c',
'member_since': 4
},
{ 'name': 'Riya',
'lang': 'Python',
'member_since': 3
},
'name': 'Aarana',
'lang': 'Java',
'member_since': 4
}])
db. EmpDetail.find({lang:'Python'})
db. EmpDetail.find().limit(2)
db. EmpDetail.find().count()
Update a row
{'name': 'Helly',
'lang': 'JavaScript',
'member_since': 51
}, {upsert: true})
{$inc:{
member_since: 2
}})
{$rename:{
member_since: 'member'
}})
Delete Row