, free & fully virtual. Register Now, free & fully virtual. Register Now

Relation Between Two different realms

I have two Tables:

  1. Restaurant - field: _id, _partition, Name
  2. User - field: _id, _partition,Name,RestaurantId
    there is a relation ship between this two table.
    No following is the record in the mongo atlas db

Ex. 1, ‘PUBLIC’ , ‘ABC’
2, ‘PUBLIC’, ‘PQR’

I want to store the user data as below:

Ex: 1, ‘Res=1’, ‘John’, 1(Restaurant obj)
2, '‘Res=2’, ‘Mike’, 2

So, I Open realm with below config.

const config = {
    sync: {
      user: user,
      partitionValue: `Res=${resId}`,
    } => {  
   UserRealm.write(() => {
            _id: new ObjectId(),
            _partition: `Hospital=${Id}`,
            patientName: patient,
            RestaurantId: {
                                   _id:'1', //Just example
                                   _partition: 'PUBLIC',
        CaseRealm.syncSession.uploadAllLocalChanges().then(() => {

It adds the data into local realm but then it is throwing an error like:

Synchronisation fail: error code: 212

Can’t we write the data like this. Can some one please help what is wrong!!

The server logs should give you more information about why this error occurs, but looking at your code, you’re opening a Realm with partitionValue: "Res=some-id", but then you’re adding objects with different partitions to it - User with _partition: "Hospital=some-id" and Restaurant with _partition: "Public". All objects added to the Realm instance must be in the same partition.