Architecting mongo db for a multi-user system

515 views
Skip to first unread message

Warren Day

unread,
Feb 27, 2017, 3:46:30 PM2/27/17
to mongodb-user
As a basic overview, I am developing a mongo based SaaS were users can create custom schemas and manage there data through a simple UI, which can then be accessed through a REST api.

A user can create an unlimited number of schemas like "cars" or "people" which could have any shape. Currently I create a new collection to store all the items of a given schema. This works fine for a single user as I can just keep creating a separate collection for each unique schema and keep the data in an organised place.

I am struggling to think of the best way to design a system that can handle multiple users. My options are:

1. Still create a new collection for each new schema type, but namespace them with the users id like 23rfsdfwqe-cars or df743sdfdd-people. I am thinking this would not scale well as the amount of users grows as you could end up with thousands of collections.

2. For each new user create a new database, keeping all of the data completely separate on a per user basis. This also wouldn't scale well as the server would have to have a ton of database collections open at once.

3. Put all items in a single collection and add the users id to the document along with the schema type. Again this would not be great as I could not index certain keys, as they could be different for every document.

What would be the best approach to this?


Rhys Campbell

unread,
Feb 28, 2017, 8:11:58 AM2/28/17
to mongodb-user
Reply all
Reply to author
Forward
0 new messages