Newbie Question on how to set up multi user data model for iOS

Hey I am a newbie to MongoDB and planning to port from SQL for my existing iOS app.

I have a question about how to structure the main database which stems from my lack of understanding of how to handle multiple users.

BACKGROUND
My app is a patient database with a bunch of relational tables but I think I know how to structure into the document model of MongoDB Realm. Currently my app does not sync to the cloud and is a local SQL database on the device itself. I have many users but their data is visible only to them on their device.

DATABASE SETUP?
My question relates to how to set up the database in mongoDB? Is it one big database on a server and each user logs in and then I filter patients related to that user on their device? Or, does each user have their own copy of the database of only their patients and each of these databases for each user is backed up to a server?

if it is one big database how do we keep any local device data limited to just that user’s data (ie I don’t want to sync some giant database back and forth between all the users who really are only ever accessing their own segment of the database).

Having asked this, I guess it would be cool to have it all on one big DB because I could look at usage trends and other analytics for users as a whole. I don’t believe the app will ever share patients with other users but it might not be a bad thing to leave it that way just in case.

Any help on this would be greatly appreciated.

Hello @Gregory_Moore.

I think your demands are exactly solved by the per user partition in MongoDB Realm, quoting from the docs:

If your application stores data privately for each individual user, you could create an owner_id field containing a specific user ID for every document. Selecting the owner_id field as your partition key would partition your database into realms corresponding to individual users.

More information is found here.

I hope that helps your usecase.