MongoDB Cheat Sheet(Beginners).
This blog contains a very basic cheat sheet for MongoDB. This blog might be helpful if you are looking for a cheat sheet.
show dbs -> to show databases
use {database name} -> To create & use a database
db.createCollection("collection name") -> To create a collection
db -> To check current database
db.dropDatabase() -> To delete/drop a database
db.[collection-name].drop() -> To delete/drop a collection
show collections -> To show collections
db.[collection-name].insertOne({key:value}) -> To insert one
db.[collection-name].insertMany([{key:value}, {key:value}]) -> To insert many
db.[collection-name].find(query(optional), projection(optional))-> To find data
db.[collection-name].find(query(optional), projection(optional)).pretty() -> To find data and prettify it
db.[collection-name].find().count() -> To count the number of data in a collection
db.[collection-name].find().sort({value:1}) -> To sort the values : -1 : Descending, 1 : Ascending
db.[collection-name].find().limit(value) -> To limit the data show
db.[collection-name].updateOne({_id:1}, {$set: {age:21}}) -> To update one set of value
db.[collection-name].updateMany({_id:1}, {$set: {age:21}}) -> To update many set of value
db.[collection-name].deleteOne({_id:1}) -> To delete
I made this basic cheat sheet when I was learning MongoDB. I thought of sharing it as it might help many beginners. If I made any mistake while writing this, you can write this in the comment's and let me know.
Top comments (0)