2 minutes
Written: 2022-06-07 00:00 +0000
Outreachy: Discussion on MongoDB vs CosmosDB
As an outreachy intern at Moja Global, I was involved in discussions about storing data in CosmosDB and MongoDB.
This blog contains my notes on the comparison of MongoDB and CosmosDB. A lot of this is written in terms of how a database server can be useful for my work at Moja Global.
Factors affecting the choice
- Better choice as document storage.
- Type of data that needs to be stored.
- Performance, storage capacity and throughput scale.
- Backup
- Cost
Comparison
-
Max Document Size:
- For MongoDB, 16MB is the maximum document size.
- While for COSMOS DB it is 2MB.
-
Integrated text search, geospatial processing:
- MongoDB supports integrated text search and geospatial processing.
- While in COSMOS DB, there is some support for geospatial data but with some limited indexing.
-
Functionality/Features:
- MongoDB provides much richer functionality to support a broader range of use cases and, crucially, more deployment flexibility, eliminating lock-in to any one cloud provider, especially with multi-cloud clusters.
- Cosmos DB can only be run as a managed service on Azure, requiring a full-scale migration if users ever want to run on another cloud provider.
-
Querying data (integrated):
- MongoDB supports integrated querying of data in cloud object storage while COSMOS DB does not.
Conclusion
Cosmos DB is good when:
- You store small documents.
- When you read more often than write because COSMOS DB writes are 5 times more expensive then write.
- You have support included in Azure subscription even for a small database.
MongoDB is good when:
- MongoDB is the only choice for documents bigger than 2MB.
- When you need freedom to create unique indexes.
- When you write data more often than read.
Though, IMO, both solutions are good for prototyping and testing.
Thanks for reading! See you in the next blog <3