All MongoDb Commands You Will Ever Need (MongoDb Cheatsheet) - CodeWithHarry
All MongoDb Commands You Will Ever Need (MongoDb Cheatsheet) - CodeWithHarry
1. Database Commands
View all databases
show dbs
OPEN
use dbName
Delete Database
db.dropDatabase()
2. Collection Commands
Show Collections
show collections
db.createCollection('comments')
db.comments.drop()
3. Row(Document) Commands
Show all Rows in a Collection
db.comments.find()
db.comments.find().pretty()
db.comments.findOne({name: 'Harry'})
Explore Amazon miniTV
On Amazon Shopping App
Always Free Always Entertaining. Your
Favourite Web Series On Amazon Shopping
App Now!
amazon.in
OPEN
db.comments.insert({
'name': 'Harry',
'lang': 'JavaScript',
'member_since': 5
})
db.comments.insertMany([{
'name': 'Harry',
'lang': 'JavaScript',
'member_since': 5
},
{'name': 'Rohan',
'lang': 'Python',
'member_since': 3
},
{'name': 'Lovish',
'lang': 'Java',
'member_since': 4
}])
Search in a MongoDb Database
db.comments.find({lang:'Python'})
db.comments.find().limit(2)
db.comments.find().count()
OPEN
Update a row
db.comments.updateOne({name: 'Shubham'},
{$set: {'name': 'Harry',
'lang': 'JavaScript',
'member_since': 51
}}, {upsert: true})
db.comments.update({name: 'Rohan'},
{$rename:{
member_since: 'member'
}})
Delete Row
db.comments.remove({name: 'Harry'})
Post Comment
Comments (21)
shaikhinamulhaq01 2022-12-01
Badhiya bhai Your content is really useful
REPLY
shoeb4dev_gm 2022-11-29
HARRY BHAI very useful but how can I download this sheet
REPLY
deepak.meena.18002_ii 2022-11-28
How to download this cheat sheet. Harry Bhai, please tell me.
REPLY
zubairsyed928_gm 2022-11-24
ThankYou Bro That's very helpful ❤
REPLY
smrutigml_gm 2022-10-22
Hey Harry, Please add commands for aggregation.
REPLY
CodeWithHarry