Logical sync problems after sync broke and was restored

Let’s set the scene:

We start with collections where the partition key was not in every collection. This was fine for 2 years or so. A few weeks ago, we paused sync, and couldn’t get it to start again, with an error that indicated that sync couldn’t start because not all the collections had the partition key. (I can’t find the details, we only have logs for the past 10 days unfortunately)

We eventually got sync to start again, in developer mode. In the App Services UI, Device Sync is listed as “Enabled” with timestamps from today:

Latest Sync Event 07/12/2022 17:40:44
Last Cluster Event Processed 07/12/2022 17:40:43
Lag 1 sec

I can login to my app, probably because Realm authentication services are still working, but I don’t get any of my app’s data. Realm studio shows the schemas I expect, but there is no data in them.

I’m getting this error message in Xcode when the sync is supposed to happen:

**Logged in**

**2022-07-12 13:55:29.722236-0400 O-FISH[2691:68876] Sync: Connection[5]: Session[5]: client_reset_config = false, Realm exists = true, client reset = false**

**2022-07-12 13:55:29.770228-0400 O-FISH[2691:68876] Sync: Connection[5]: Connected to endpoint '34.227.4.145:443' (from '192.168.4.45:52739')**

**2022-07-12 13:55:30.211263-0400 O-FISH[2691:68876] Sync: Connection[5]: Session[5]: Failed to transform received changeset: Schema mismatch: Link property 'user' in class 'DutyChange' points to class 'User' on one side and to 'DutyChange_user' on the other.**

**2022-07-12 13:55:30.211458-0400 O-FISH[2691:68876] Sync: Connection[5]: Connection closed due to error**

This is open source code - the models can be seen at:

and

In App Services UI, under the “Schema” tab, we had this:

We tried deleting the DutyChange schema, and had the same issues with the app.

Then we tried clicking the “Use Schema Dev Mode” on the Schema page for DutyChange, which sent us to the device sync page - which is already enabled, and in dev mode.

Then we tried regenerating the DutyChange schema using the UI’s “Generate Schema” button, and had the same issues with the app.

Any tips to get sync working again? Local objects are being made, and our logs show no errors - the relevant Sync->Other logs show things like:

“Client bootstrap completed in 16.903915ms. Received 1 download(s) containing 2 changeset(s) (14.3 kB total).”

The data does not get fully sync’d to the Atlas collections, though. And information that is supposed to sync to the device, based on the partition key, does not show up - we have some menus that are populated with data from Atlas, and those menus are empty.

Any ideas?

Hi, can you send a link to your app in realm.mongodb.com and I can try to take a look? It seems to me like your json schema for the user-sub-object is missing the “title” field, since if we do not find that we give the sub-object a table name of “ParentTable_FieldName”.

Thanks,
Tyler

1 Like

Hi @Tyler_Kaye thanks for the reply - indeed I was missing the “title” on both DutyChange.user and DutyChange.user.name.

I changed it, but I’m still seeing the same problems with my app - I deleted it off my device and re-built it from Xcode, with the same issue. Normally I’d try to pause sync and restart it, but since that caused problems last time, I’m a bit shy about doing that.

The URL for my realm schema - App Services

Here’s a snippet of what I changed - I added the title in 2 places, as indicated by <— (the arrow is not actually in the code itself)

    "user": {
      "title": "User",           <---
      "bsonType": "object",
      "required": [
        "email"
      ],
      "properties": {
        "email": {
          "bsonType": "string"
        },
        "name": {
          "title": "Name",        <---
          "bsonType": "object",
          "properties": {
            "first": {
              "bsonType": "string"
            },
            "last": {
              "bsonType": "string"
            }
          }
        }
      }
    }

Hi @Sheeri_Cabral1 ,

It looks like you’ve connected two different Data Sources to your app, so your schema shows two different versions of the same objects: sometimes they match, sometimes they don’t.

If you look at your Data Models, you’ll find that you have both

class DutyChange: Object {
    @Persisted(primaryKey: true) var _id: ObjectId
    @Persisted var agency: String = ""
    @Persisted var date: Date = Date()
    @Persisted var status: String = ""
    @Persisted var user: DutyChange_user?
}

and a different

class DutyChange: Object {
    @Persisted(primaryKey: true) var _id: ObjectId
    @Persisted var agency: String = ""
    @Persisted var date: Date = Date()
    @Persisted var status: String = ""
    @Persisted var user: User?
}

You may want to double-check the setup, and make it consistent.

1 Like

Ooh! Thanks, I had no idea where to look for those! Just for anyone else reading, it was the same solution as Tyler - fix the JSON schema - except I had 2 places to change it.

It’s still not working, I’m getting a more common error that the Name.first property is nullable on one side and not the other; I just have to figure out which collection’s schema that’s referring to, a lot have that property!

Thanks.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.