MongoDB CheetSheet [In Progress]
This guide includes an introduction to MongoDB, a glossary of terms and lists of commonly used MongoDB commands with example.
So here we go,
Introduction
- Mongodb is a non-relational database which means it does not use the tabular schema of rows and columns found in most traditional database systems like MySql.
- The second thing about mongodb is that it stores data in a key-value pair.
- The third thing about the mongodb is that the attribute _id which is unique and it is automatically created by Mongodb so chill 😎
MongoDB commands
- Create Database:
- use <Database Name>
- Create Collection:
- db.createCollection(<"Name">,{<Option>})
- Insert One document in collection:
- db.<Collection-Name>.insertOne([{<document>}])
- Insert Many Documnets in Collection:
- db.<Collection-Name>.insertMany([{<document1>},{<document2>}])
- Find a particular row:
- db.getCollection("<Collection-Name>").find({<column-name>:"<Unique Name/Id>"})
- To check which db is selected:
- db
- To check all databases who has at least one collection or document
- showdbs
- To drop a database:
- db.dropDatabase()
- To drop a collection in database:
- db.<collection-name>.drop()
- To see collection:
- db.<collection-name>.find()
- To check the version of mongodb:
- db.version()
Comments
Post a Comment
Please give us your valuable feedback