Introduction to MongoDB: A NoSQL Database

Naveen Singh
3 min readDec 25, 2020

What is Database?

In home you have refrigerator or fridge to store food, veggies and other items, so in electronic/digital world the food is called data and the refrigerator is known as Database.

What is NoSQL database?

Before NoSQL lets understand what is SQL database. SQL database has a defined structure to store data or information that is in the form of table(Row, Column) just like your refrigerator’s cabinet(well defined space).

SQL Database example

From above figure it can be noticed that all the data is in row, column format and none of the data is null. If any data is null or empty we have to write null there.

In NoSQL database there is no fixed structure that is there is no fixed number of column and the number of column can be different for individual entry or row.

MongoDB is a NoSQL database. Here are some points to be noticed:

  1. Just like “table” in SQL database, MongoDB has “collections” where all the information is stored.
  2. In table we have rows and column then in collection we have “document” that contains “key value pair”. Column is called Key here.
  3. For example: Column name is “City” and for the first row the value is “Kanpur”. This can be written as{ “City” : “Kanpur”} for the first Document(first row). We will talk about it later.
  4. The document is stored in JSON format.
brief

To download MongoDB, click here and for installing video tutorial click here.

Let’s do some practical:

To start MongoDB, first set the path in cmd then type “mongod”. Then open another cmd and type “mongo”

First Step
Second Step

Don’t close any window till our operation completes.

We can create multiple document at a time using: db.datatype.insert([{document1},{document 2},{document n}])

OPEN THE IMAGES AND ANALYSE WHAT IS HAPPENING. ALSO READ THE PARAGRAPHS AND LINES WRITTEN OVER THERE.

We learnt how to insert document in collection. Now we will see how to find the required document in the list of document.

What if we have condition like less than, not equal, greater than etc then we have to use:

take the first letter of both less than i.e. l and t so we wrote $lt and so on.

greater than = gt, less than =lt, not equal=ne, less than or equal to=lte, etc.

Now how to delete collections, documents and database too:

Before deleting the database first run the command “db” to check the current db.

Next time we will cover method and functions

If something is wrong please comment down below.

Thank you for reading!!!

--

--