Skip to main content

What is MongoDB

MongoDB is an document-oriented database that is designed to store a large scale of data and also allows you to work with that data very efficiently. It is a NoSQL (Not only SQL) database because it uses a document data model, different from the tabular databases that store data with relational tables.

The best way to start understanding MongoDB basics is to grasp the following comparison:

MongoDBTraditional SQL
DatabaseDatabase
CollectionTable
DocumentRow
$lookupJoin
IndexIndex
ACID TransactionACID transaction

The MongoDB database contains collections just like the MYSQL database contains tables. You are allowed to create multiple databases and multiple collections in each database.

Inside of the collection we have documents. These documents contain the data we want to store in the MongoDB database. MongoDB can handle dynamic data models (flexible schema) and schema that can easily store unstructured data sets.

MongoDB sample document

The documents are created using the fields. Fields are key-value pairs in the documents, like columns in the relation database.

The value of the fields can be of any BSON (Binary JSON) data types like double, string, boolean, etc.

The data stored in the MongoDB is in the format of BSON documents, and this BSON is stored and queried more efficiently.

In MongoDB documents, you are allowed to store nested data. This nesting of data allows you to create complex relations between data and store them in the same document which makes the working and fetching of data extremely efficient as compared to SQL. In SQL, you need to write complex joins to get the data from table 1 and table 2.

The maximum size of the BSON document is 16MB.

If you're new to the document model, check out our series on data modelling for MongoDB.