I am a little confused about partition keys to get MongoDB Realm and Atlas working together. In particular, I am referencing the material at https://docs.mongodb.com/realm/sync/partitioning/
Whilst there are a couple of examples in the documentation, my use case is a little different. My users create documents - notes
, and often they will share those notes
(with either read or write permissions) to one or more other users. They may also not share with any other users, likewise, they may also add new shares with additional users or un-share existing users during the lifecycle of a notes
document.
The Team Realms example wouldn’t suit here because the users that a document is shared with is not always going to be consistent across documents. So having this alternative teams
collection would not suit.
So my thought process…
I currently have two fields in a notes document - sharedViewers
and sharedEditors
that contain the relevant user IDs where the document is shared with other users.
But I’m then confused about how to deal with the partition key and the realms that are then created locally on users devices.
In addition I noted that the documentation states that:
Avoid changing a partition value in a Realm object using the Realm SDK because it triggers a client reset.
- So could this client reset be an issue?
- If this approach then creates n number of realms every time documents are shared with a user, then querying across all realms is not possible correct?
Any help would be appreciated as I’m surely not the first that is trying to deal with this type of use case.