Partitioning a shared schema

According to the documentation “Realm clients should never modify the partition value directly”

This suggests to me that the partition should be set upon object creation and never modified. Do I understand that correctly?

If so, what is the best practice for handling partition changes?

Here’s a scenario:

User creates a document.
If I set the partition of these documents to the _id of the user who created them, we can easily open a realm on that _id and synch is straightforward.

Now, what if I want to allow another user to synch that document?
Given that I cannot (or should not?) modify the partition after it has been created…

Would this partitioning strategy work?

Set the partition on the document to something like this on creation:
author=1234&reader=4321editor=1243

And maintain keys on the user document for reading and editing which reference lists of all of the reader or editor id’s that a user has been invited to.

So, when a user shares a document, I would register id’s to the user documents…
Something like this, for instance:
reading = [4321]

Then, for the user which has been invited to read the document, I would open a realm on the partition:
reader=4321

The problem here, as I understand it, is that, if a user is invited to read a lot of documents, I potentially have to open a ton of realms.

Is there a better strategy for this type of schema?

1 Like

Hi, I would definitely think about using Flexible Sync. It is currently in Beta but it provides a more “flexible” syncing experience by removing the limitations associated with partitioning. In your case you could make author, reader, and editor “queryable fields” and have users be able to craft queries using normal Realm Query Language syntax.

See here: Introducing Flexible Sync (Preview) – The Next Iteration of Realm Sync | MongoDB
Documentation: https://docs.mongodb.com/realm/sync/data-access-patterns/flexible-sync/

Thanks. I’ll take a look.