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

  1. Better choice as document storage.
  2. Type of data that needs to be stored.
  3. Performance, storage capacity and throughput scale.
  4. Backup
  5. Cost

Comparison

  1. Max Document Size:

    • For MongoDB, 16MB is the maximum document size.
    • While for COSMOS DB it is 2MB.
  2. 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.
  3. 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.
  4. Querying data (integrated):

    • MongoDB supports integrated querying of data in cloud object storage while COSMOS DB does not.

Conclusion

Cosmos DB is good when:

  1. You store small documents.
  2. When you read more often than write because COSMOS DB writes are 5 times more expensive then write.
  3. You have support included in Azure subscription even for a small database.

MongoDB is good when:

  1. MongoDB is the only choice for documents bigger than 2MB.
  2. When you need freedom to create unique indexes.
  3. 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