Is MongoDB really Schemaless?
By now it is well known that the MongoDB is Schemaless. We need to understand what is that makes the MongoDB beahve as a schemaless database.
Every RDBMS database will possess a structure with respect to persisting the data. So, when the database needs to be modified, say a column of particular table needs to be modified(changing the datatype) or adding/removing a column from a table, we have to mention, what type of data this column will hold.
But, MongoDB is a document based database, which does not use the concept of tables and columns, instead of which it uses the concept of documents and collections. All the referential data with respect to different modules will be stored as one collection. More over the BSON data structure used by MongoDB can easily have varying sets of data and fields with different types.
When we say schemaless, we actually mean dynamically typed schema, as opposed to statically typed schemas as available in RDBMS(SQL) databases.
JSON is a completely schema free data structure, as opposed to XML which allows you to specify XSD if you need.
Whenever we store something in MongoDB, we know what we are storing, its a String, Int or a custome Object in JSON format, and as soon as we try to store it in a collection, MongoDB accepts it as a JSON formatted data.
And when you read somewhere that data migration is easy in NoSQL databases, its also not absolutely true. There are certain scenarios where document based databases like MongoDB proves to be better, but there are scenarios where SQL based databases have the upper hand. For example : data processing while migrating, takes longer in case of NoSQL due to data duplication, while in a Normalised SQL database, minimal data duplication is there.