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:

  1. RDBMS (Relational Database Management System)

Why we use MongoDB{NoSQL} !

Ans:

  • Scalability

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 that click to free cluster or click to connect button

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.

Here we give our database name customer_list and collection name is detials

When our database is created successfully then we get a interface like below :

details is our collection name with zero documents

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).

we want to add data indetails collection of our customer_list database

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:

look how we enter data in MongoDB

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 .

after insert the 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 .

check both two 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 .

Look Sourav document right side we have update button and datatypes are also showing in side

Drop database :

To drop the database we just need to type database name after clicking dustbin symbol .

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store