How to handle different types of Documents

Hi,

Quite new to mindset of NoSQL in general and MongoDB and Realm in particular.

Let’s say I have an application where documents can be:

  1. systemwide (hardcoded) and readonly: different types of car make and models
  2. user-based: users actual cars
  1. should be edited serverside and available to user as readonly whereas 2) are created and edited by users (and owned) by that user. user-based documents should only be visible to the owner of that document.

What type of access control, permissions do I use? It seems to depend on variety of factors, i.e. Partition-Based Sync or Flexible Sync.

It’s important that only systemwide documents and documents that the user owns (has created themselves) are synced to their device. Is this controlled by “read”?

BR,
Jimisola

So while this is a pretty good question, it’s going to be hard to answer because there are too many variables and use cases. Also, some of the terminology being used is not clear; for example edited serverside could mean a LOT of things. I would doubt that you’re planning on sitting on a computer accessing the “server” (Realm console) to input data - you may, but that’s highly inefficient.

You’re overall setup will also be be different between partition and flex sync. With partition, you could have all of the items that are read-only on one partition that everyone has access to, and then each user could have their own partition. The downside there is that while the user sync’s to their partition which could be a small amount of data, the read-only partition dataset could be massive - or maybe not. So then you consider flex sync

Without knowing a lot more info, it’s going to be hard to make a suggestion, other than think through those use cases and write some code to see what works.

I agree with Jay that there are a lot of variables here.

That said, in this particular situation, I have a suggestion to learn about Flexible Sync and focus on optimizing that for your situation.

Flexible Sync appears to be the future of Realm and partition is pretty legacy. Even if there was a crystal ball showing both would fit your data situation equally well, from a skills perspective I think it makes sense to go with Flex sync. More likely to continued to be used in the future with the current product or others, and then you don’t have a possible deprecation situation later on. Also cross training/documentation will live longer.

Anyway, enough hypothetical… sounds like flex sync is the way to go for your situation with a “ownerId” queryable field on your documents that you apply permissions to.

For all the ‘system’ documents, have the owner id set to a specific value and limit who can modify based off that. You can still give read access to everyone.

For user documents, set the ownerId to the given user and limit permission based on that.