MongoDB groundwork [A basic lesson for MongoDB compass]
by ahin subhra das
MongoDB is a No SQL database. It is an open-source, cross-platform, document-oriented database written in C++. MongoDB is a object oriented database.
History of MongoDB : MongoDB was developed by a NewYork based organization named 10gen which is now known as MongoDB Inc.
Database types :
Databases can be divided in 3 types:
- RDBMS (Relational Database Management System)
- OLAP (Online Analytical Processing)
- NoSQL (recently developed database)
Why we use MongoDB{NoSQL} !
Ans:
- Scalability
- High Availability
- Scaling from single server deployments to large, complex multi-site architectures.
- Key points of MongoDB
- Develop Faster
- Deploy Easier
- Scale Bigger
Difference between MongoDB and MySQL :
MongoDB Install : “http://www.mongodb.org/downloads"
And after that follow the instruction install MongoDB compass also .
HomeView of MongoDB compass :
After entire in the server we need to create a new database . For creating a new database we need to click create database button after that we need to define our database name and our collection name .
In MongoDB A collection is a grouping of MongoDB documents. Documents within a collection can have different fields. A collection is the equivalent of a table in a relational database system. A collection exists within a single database.
When our database is created successfully then we get a interface like below :
Now we want to add data in our collections for that we need to click in details , there we have two options one is Import file(already created MongoDB file), and another is Insert document (add data as you want).
In MongoDB, the documents are stores in BSON, which is the binary encoded format of JSON and using BSON we can make remote procedure calls in MongoDB. BSON data formate supports various data-types.
Insert document:
In above image we have $oid [object id ] that is provided by MongoDB server , After that we need to separate next field with a comma . Then we add name , address and email of customer . Remember one thing you must give comma between two fields .
Check below picture we successfully create our first document of data .
One by one we can add the data in database . But we must check a difference between MySQL and MongoDB. In the below image look we add another document , where customer name is sourav we have a field age but in 1st felid we don’t age . In MySQL we must have same field in every data .
Update document :
Easily we can update our document using add a field and after that we have a update button to update document value .
Drop database :
To drop the database we just need to type database name after clicking dustbin symbol .