Is MongoDB really Schemaless

Welcome to a tutorial on MongoDB. Here you see the answer to the question ‘ is MongoDB really Schemaless?

We will learn what makes the MongoDB behave as a schemaless database. 

All RDBMS database possesses a structure with respect to persisting the data. So, when the database needs to be modified (e.g. a column of a particular table needs to be modified, either by changing the datatype or adding/removing a column from a table), we have to mention the datatype this column will hold.

 

MongoDB

Although MongoDB is a document-based database, meaning that it doesn't use the concept of tables and columns, instead it uses the concept of documents and collections. Therefore, all the referential data with respect to different modules will be stored as one collection. However, the BSON data structure used by MongoDB can easily have varying sets of data and fields with different types. Therefore, just as we saw, schemaless means dynamically typed schema, as opposed to statically typed schemas which are available in RDBMS (or SQL) DB.

 

In addition, JSON is a schema that is a completely free data structure, unlike the XML which allows you to specify XSD if you need.

 

However, anytime we store something in our MongoDB, and what we are storing could be a String, Int, or a custom Object in JSON format, and, also as soon as we try to store it in a collection, MongoDB accepts it as a JSON formatted data.

So, therefore, many articles might say that data migration is easy in NoSQL databases, but it's also not absolutely true. However, there is a certain situation where document-based databases like MongoDB might prove to be better, while for others, SQL-based databases have the upper hand. Take, for instance, data processing while migrating, which takes longer in the case of NoSQL due to data duplication, but in the case of a Normalised SQL database, minimal data duplication is there.