MongoDB | Update your DS Resume with [NoSQL]| {PART-1}

Saikiran Dasari
6 min readDec 18, 2022

--

Introduction:

MongoDB is an extremely popular database, and it can be used in different kinds of applications, such as desktop applications, mobile applications, or only in the backend for Data Science.

In this Blog, I’ll be explaining all about MongoDB and installation setup for all the required things on your local machine to get started with MongoDB.

Image Source

Relational vs Document Database?

There are two most common types of databases -Relational databases or SQL databases and Document databases or NoSQL databases.

Examples of relational databases are MySQL, PostgreSQL, Oracle and etc.

In SQL databases data is stored in different tables and those tables have a fixed schema.

Data that is stored in those tables have relations such as one-to-one, one-to-many or many-to-many.

And to retrieve some data from the relational database you usually perform a join request that combines data from different tables.

In Document databases (MongoDB) data is stored in separate documents and each document is independent of the others.

And it is not mandatory to have the same schema for all documents.

For example, some documents in the database may have a field called “City” but other documents in the same database may not have this field.

MongoDB structure

Each MongoDB database consists of databases.

There are default databases that are created after each installation of MongoDB. And they are called for example admin and local.

Each database consists of collections and each collection consists of documents.

The reason why it is not strict is that the Data is Stored in Document Oriented Approach

So what is DOA? Usually, all the data is in the form of a JSON Document

Data Formats in MongoDB

JSON (JavaScript Object Notation)

JSON is usually used for data exchange and it is represented as a string.

Inside it is an object with key-value pairs.

All keys must be surrounded by double quotes and JSON supports six data types

Here all the data is stored in a KEY: VALUE pair (Usually the retrieval of the data becomes very very Quick

BSON Format (Binary JSON)

Data is stored in BSON format in MongoDB instead of JSON

JSON supports only 6 data types but BSON supports more

Extended JSON

Extended JSON is used for the representation of the data, that is stored in the BSON format, in a readable format. It is also used to store new documents in the BSON format.

In other words, using Extended JSON you can give instructions for MongoDB on which types should be used for values that you pass to the MongoDB

Main things to Notice:

FIRST:

Since it is stored in a Key: Value pair the retrieval of the data becomes very Fast,

Ex: Suppose if Students Collections (Note: We don’t say tables in MongoDB)

In one of the Records I have data in the form of a JSON document, and suppose I don’t have one property like Age, But, for the next record, I can add that particular property, and because of this it becomes Dynamic schema!

For each and every JSON document we can add any number of properties as per requirements!

SECOND:

It supports GEOspatial Query

Eg: Recommendation System, and If I want to recommend something to the users based on the Geolocation. (Based on location and Radius we can recommend something to the users)

This Geolocation is the longitude and latitude where the person is there!

Suppose a person is standing in one particular place, that particular Geolocation will actually be captured in MongoDB.

So, with that info like longitude and latitude, we can Query it out! Not only that we can cover the Radius around it!

Suppose, if I give an additional 50 KMs radius around that particular Geolocation, we can easily Query it!

THIRD:

Integration with BIG DATA HADOOP

It can be easily integrated with BigDATA Hadoop, Internally big data Hadoop has a system internally called as Map-Reduce(You basically map some data then you try to convert that data in some format which is reduced). Similarly, MongoDB has the same thing

FOURTH:

Since the data is stored in DOCUMENT Oriented Approach, so, the way we query the data is powerful as SQL

FIFTH:

It can be easily installed and is Highly Scalable,

Performance is very HIGH.

LIMITATIONS:

Suppose you have High Transactions happening in the system, Please never use MongoDB

In Banking, we need to use SQL database (Over there the Schema is fixed for SQL) but in the case of MongoDB the Schema is Not — fixed

MongoDB is not good for tightly coupled systems(the system which interacts with each other in a strict manner

MongoDB Shell and MongoDB Server

The “mongod” command is used to launch MongoDB Server and the “mongosh” command is used to launch MongoDB Shell.

NOTE: The mongo command line tool has been superseded by the new mongosh tool. Starting in MongoDB version 6.0 mongo is no longer being installed, but the installer should have installed mongosh.

Those two applications are separate but what do those two applications do? MongoDB Server stores data in the MongoDB database.

It is the main point of data storage.

Mongo shell is used for the management of the mongo server.

Using mongo shell you can insert documents into the mongo server, you can update documents, can delete documents, and so on.

In other words, you can perform all kinds of CRUD operations -

Create, Read, Update and Delete.

Installation: MongoDB Server | Compass | Shell

For the Sake, I’ll be showing installation in Windows, Similar Steps can be carried out for Mac, and Linux Users

Always refer to MongoDB Documentation! Click on the Below Link to Redirect to Download Page:

Go through my GitHub MongoDB Repo for MongoDB Installation Screen Shots which I prepared when I installed it (LATEST)

Conclusion:

In this article, we discussed the MongoDB Overview

- Where MongoDB is Used?

- Relational vs Document Database

- MongoDB structure

- MongoDB Shell and MongoDB Server

Some Key Takeaways from this article are:

1. Data Formats in MongoDB (How data is stored in the database -> It is stored in BSON format. Extended JSON is used for the representation of the BSON format in a readable format)

2. Main things to Notice: (Data is stored in a Key: Value pair the retrieval of the data becomes very Fast)

It supports GEOspatial Query. Since the data is stored in DOCUMENT Oriented Approach, so, the way we query the data is powerful as SQL, It can be easily installed and is Highly Scalable

3. Limitations: Suppose you have High — Transactions happening in the system, Please never use MongoDB

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

Part-2: The Next Connecting Piece of this MongoDB Specialization will be purely based on the PYMONGO library and How to Bridge a connection between Python and MongoDB and MongoDB Atlas connection and my GitHub resources where you can have access to my code and document content

It will be one of the extremely useful Blogs and I will be providing coding resources so you can practice / hands-on yourself.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

I have tried to write a detailed article and I hope that I am successful in doing so. I’ll try to keep on adding More Content that will link to each other!!

Thanks a lot for your time, and I will get back with another interesting topic shortly! Till then, bye! — Saikiran

— — — — — — — — — — — — — — — — — — — — — — — — — — -

💬 Leave a response to this article by providing your insights, comments, or requests for future articles. 📢 Share the articles with your friends and colleagues on social media.

If you liked this blog, consider following me on @MEDIUM, LinkedIn, Twitter, and GitHub for more content.

@Saikiran Dasari | Portfolio or Saikiran Dasari | Email to contact me.

The media shown in this article is not owned by MEDIUM and is used at the Author’s discretion.

--

--

Saikiran Dasari

Hi there, I’m a Data Scientist& CompScienceEngg, I like working on Data: Extraction, Pre-Processing & EDA, Feature-Engg, Modelling, NLP, Time-Series, Deployment