MongoDB Database Design for SaaS ERP

Hello everyone,

I’m working on a project where I need to design a MongoDB database to store information related to multiple companies. Each company has a specific set of invoices, accounts, and other documents, each with its unique particularities.

I’m considering two approaches to the design:

  1. Single database with unified collections for all companies: In this structure, all data from every company would be stored in common collections. For example, there would be one “Invoices” collection where invoices from all companies would be saved. Each document within this collection would have a field, like “companyId”, to identify to which company the document belongs.

  2. One database per company: Here, each company would have its own database, and within that database, it would have specific collections for invoices, accounts, etc. Thus, there would be a “CompanyA” database with an “Invoices” collection, and another “CompanyB” database with its “Invoices” collection.

Given that on average each company would have around 15 collections, I would like to get advice on which of these two structures would be more advisable.

My primary concerns are:

  • Performance and efficiency in terms of reading and writing.
  • Scalability as more companies and documents are added. (future sharding)
  • Management complexity (e.g., backups, replication, monitoring).
  • Data security and isolation for each company.
  • Mongodb Limits (Link)

What recommendations or experiences can you share regarding this?

Thank you in advance for your assistance!