MongoDB and DocumentDB – The Functional Differences and Advantages
MongoDB vs DocumentDB
With the invention of newer technologies, some of the flaws of the traditional relational database scheme have become evident. If we consider Big Data Analytics then the sheer quantity and lack of structure make it difficult to implement it using RDBMS. This is where NoSQL steps in. NoSQL is an approach that incorporates several data models, such that it can handle all sorts of structured, semi-structured and unstructured data sets. There are several services that offer NoSQL such as DocumentDB, MongoDB, CouchDB etc.
In this blog post, we are going to talk about two in particular - DocumentDB and MongoDB. for more techniques go through MongoDB online training
The Similarities of MongoDB and DocumentDB
MongoDB and DocumentDB are two APIs which can be referred to as CosmosDB resource in Azure. Here, the data is stored in documents, which are then collected and they collectively form a database. There are some evident similarities and differences between both of them. The similarities are:
- The format in which data is stored in the document is JSON or JSON like formats, such as BSON. Since JSON is a universally accepted format, this makes it easier to integrate it with other systems.
- The documents can be easily queried and obtained using querying languages, that are similar to SQL.
By contrast, MongoDB was not intentionally built to run in a PaaS environment from the ground up. Historically, MongoDB was designed and built to run on low-cost hardware running on Linux. Soon afterward, MongoDB was given support for running on Windows operating systems (although mainly for cost reasons most real-world production environments use Linux clusters exclusively).
It should be no surprise to know that MongoDB retains all the benefits of running in a user-managed environment but also incurs the challenges of managing that complexity as well. That said, it is possible to run MongoDB in Azure Cloud as both IaaS and PaaS. MongoDB online course helps you to learn more effectively.
With IaaS, the setup is fairly straightforward like configuring any other virtual machine (note: there is no specific "MongoDB" VM template so you will have to instantiate your own Linux/Windows VM instance and then install MongoDB). With PaaS however you are in for a treat. To set up MongoDB running in a PaaS environment, such as Azure Web or Worker roles, is a non-trivial affair with very limited documentation to support the process.
Advantages of MongoDB
- MongoDB has a feature called aggregation pipeline where multi-stage filtering can be implemented so that it can procure documents from a collection and provide a crisp, filtered output. DocumentDB can handle only simple SQL-like queries.
- MongoDB provides us with full-text indexes, while DocumentDB doesn't.
- Another feature unique to MongoDB is the 'map reduce'. The data from the collection is made to go through two stages that repeatedly filter it before projecting the output.
- One major advantage that MongoDB has over DocumentDB is the fact that MongoDB is a service in its own, so it can easily be integrated with multiple platforms, unlike DocumentDB, which runs on Azure.
Advantages of DocumentDB
- DocumentDB is basically designed to integrate server side Javascript functions into its working. Strictly speaking, MongoDB can handle some server side Javascript functions, but it is severely limited compared to that of DocumentDB.
- A key feature of DocumentDB is that it can perform Acid functions, while MongoDB can only be atomic in each document. This is more of a disadvantage of MongoDB, rather than an advantage of DocumentDB.
- When it comes to indexing, DocumentDB has a rather over-the-top approach. It fully indexes everything. This results into good performance. It should be mentioned, however, that it is possible to implement custom indexing policies, to provide better control over what is being indexed.
- A very important feature of any NoSQL service is scaling, and DocumentDB makes it very easy to set up a world-wide cluster, with options for everything from consistency levels to configuring failovers for potential errors. Again, this is possible in MongoDB, but it is relatively limited and also, much harder.
- DocumentDB, as a part of Azure, provides built-in security as well.
Conclusion
There are several factors to consider when selecting which NoSQL service to use for your purpose. If your task requires complex filtering from all the documents in the collections, then MongoDB with its aggregation pipelining and map-reduce features would be a better choice. If it can be implemented with simple SQL like queries, then maybe DocumentDB could handle your task. Also, if your task requires multi-document ACID transactions then DocumentDB should be selected. Not to mention, if server-side Javascript functions are required, then probably you should go for DocumentDB. for more info MongoDB online training India
There are several advantages to each service, and proper research must be conducted so that a learned decision can be made.