How MongoDB Works


Mongodb_vs_Sql

MongoDB is a document-oriented, NoSQL database that stores data in a JSON-like format, which is often referred to as BSON (Binary JSON). Unlike traditional relational databases, MongoDB does not use a fixed schema or table structure, but rather stores data in flexible and dynamic documents.

Here's how MongoDB works based on the following points:

Database :

In MongoDB, a database is a container for collections. It is where all the data is stored. You can think of a database as a namespace for collections. You can create as many databases as you need, and each database can have one or more collections.

Collections :

A collection in MongoDB is a group of related documents. It is similar to a table in a relational database, but without a fixed schema. You can add or remove fields to a collection at any time, without affecting other documents in the collection. A collection can have one or more indexes, which can be used to optimize query performance.

Documents :

A document in MongoDB is a JSON-like data structure that represents a single instance of data. It is similar to a row in a relational database, but with a more flexible and dynamic structure. A document can contain any number of fields, which can be of different data types, and can have nested structures.

Database Collection

Documents in a collection do not have to follow a fixed schema, allowing for more flexibility in data modeling. For example, one document in a collection could have additional fields compared to other documents. This schemaless approach is one of the key features of MongoDB.

To summarize, MongoDB stores data in a JSON-like format, with a flexible and dynamic structure, without a fixed schema. Data is organized into databases, which contain collections of related documents. This document-oriented approach offers greater flexibility and scalability than traditional relational databases, making it popular for web and mobile applications that require high performance and scalability.


DescriptionMySQLMongoDB
Data StorageTablesCollections
Data RecordRowDocument
FieldColumnField
IndexIndexIndex
Primary KeyPrimary KeyPrimary Key (automatically created for the _id field)
Query LanguageStructured Query Language (SQL)MongoDB Query Language (MQL)
Joining TablesJOIN clauseEmbedded documents or manual references
TransactionsACID-compliant transactionsMulti-document transactions (in recent versions)
ReplicationMaster-slave replicationReplica sets
ShardingPartitioning based on a sharding keySharding based on a sharding key or hashed shard key
Data ModelingER modelingNo fixed schema, document-oriented data modeling
Use CasesTraditional data-driven applicationsWeb applications, real-time analytics, and high-volume transactional systems