Understanding partitions for PUBLIC vs private data

I’m struggling to understand a couple things about partitions and Realm Sync.

I’m currently in Development Mode. I’ve create some data using the _partition key with the value of “PUBLIC” which should be accessible by all users. Additionally I’ve created some private data using the _partition key with the user’s ID string.

  1. In order for the user to sync both their private and PUBLIC data, do I need to “asyncOpen” both Realms with the _partition key set to “user.id” and “PUBLIC” respectively?

  2. My private data contains links, or lists of PUBLIC data. If I try the above (with two realms) when I try to write private data which references the PUBLIC data I get the following error: ‘Object is already managed by another Realm. Use create instead to copy it into this Realm.’

  3. Since I’m in Development Mode my expectation is that none of this should be happening right now. All data in my DB should be sync with my user, regardless of what the partition key value is under a single Realm connection instance.

  4. Also in Development mode, I would expect that I could write new data to my DB using the same Realm connection instance, but using different values for the _partition key. For example, perhaps my user would like to write PUBLIC data, they should be able to do that under the Realm instance that was opened with the partition key being their user.id, no?

Fundamentally, my hope is that I can open a single Realm instance on the client, using the _partition key of my user and sync both the user’s private and all the PUBLIC data in the Realm. At least this is what I gather is possible from the documentation.

Can someone help me understand what I’m missing and if the above is possible?

@Brad_R

  1. Yes

  2. Realm relationships do not work across realm boundaries. Instead use a manual reference or “foreign-key” concept. For instance, you could have a field in your private realm object that is a string which refers to the id in the PUBLIC realm - you then run that query in the public realm.

  3. Not sure what you mean here. You may need to wipe your simulator to redownload the data from the server.

  4. You can do this - you can have multiple realms on the client that each correspond to different partitionKey values. In your app code you hold a different variable references to each realm - ie. publicRealm or privateRealm

OK. I think I understand now.

#3 I meant, being able to sync different partitions with one instance, you you’ve clarified in another response.

Appreciate the response. I think I need to do some more thinking about to structure data in different partitions data cannot he access across realms.

Thanks again