Difference between MongoDB and SQL

I got to know through search that Mongodb uses indexing to save the data so how it is different than SQL in that basics. I have the idea that MongoDB stores the data in JSON whereas SQL stores it in form relation. Could anyone explain to me about it in little dept and the concept behind it?

Hey @jaygala24

So a little overview of MongoDB from top down:

  1. The mongod, running instance usually referred to as a node:

mongod is the primary daemon process for the MongoDB system. It handles data requests, manages data access, and performs background management operations.

1.5. (Advanced) Can have more than one node which can make up a replica set or sharded cluster

  1. Clients/Driver connect to the mongod. Or via the mongo shell

  2. When connected you can create databases

  3. Inside a database are collections

  4. Documents are stored in collections

MongoDB stores documents in collections. Collections are analogous to tables in relational databases.

MongoDB stores data records as BSON documents. BSON is a binary representation of JSON documents

MongoDB documents are composed of field-and-value pairs

MongoDB is basically schema free; therefore the documents in the same collection can have any number of different fields. This also allow a user to add or remove fields from a document without having any restructuring.

This document model allow users to embed documents directly inside of other documents, which allow you to represent hierarchical relationships like arrays, and other complex structures without the need of joins.

Indexes are used in Mongo to improve query performance.

Without indexes, MongoDB must perform a collection scan , i.e. scan every document in a collection, to select those documents that match the query statement

Hope that helps.

An analogy from using JavaScript: A database is like a file(index.js) with a collection like an array, which holds documents that are like objects


Thanks for help :grinning:

Hi @jaygala24,

In addition to @natac13’s reply, you can also refer to the following link for more details:

Please let me know, if you have any questions.