Cannot sync data with embedded realm objects

Hi,

I’m trying to embed two objects according to this explanation

class AccessibleDataTest: Object {
    @Persisted(primaryKey: true) var _id: ObjectId = ObjectId.generate()
    @Persisted var place = ""
    @Persisted var accessibility: AccessTestItem?
    @Persisted var accessAddress: AccessTestAddress?
}
//
class AccessTestItem: EmbeddedObject {
    @Persisted var bell: String = ""
    @Persisted var ramp: String = ""
}

class AccessTestAddress: EmbeddedObject {
    @Persisted var postcode:String = ""
    @Persisted var houseNumber: String = ""
}

I’ve uploaded data via Atlas Compass.

{
  "place": "Alice's Tea Cup",
  "accessibility": {
    "elevator": "elevator",
    "ramp": "ramp",
    "bell": "bell",
  },
  "address": {
    "postcode": "10023",
    "houseNumber": "102"
  }
}

When I run device sync, the realm doesn’t sync the data on Atlas db into the local sync realm file. But it does sync a non-embedded object.

Is there a step I am missing?

So the key here is that I am using Flexible Device Sync.

After spending two days trawling the internet, reading the documentation about realm objects, changing the Embedded Object to a list of Embedded Objects, looking at the realm ios github examples, reading the documentation on subscriptions, by luck, I found the answer here in the fourth response:

Is it possible to define a subscription with a query on a field that belongs to embedded object?

Unfortunately it is not. See here: https://mongodb.prakticum-team.ru/docs/atlas/app-services/sync/data-access-patterns/flexible-sync/#eligible-field-types

Clicking through the link to the documentation, there is one paragraph that says:

Flexible Sync does not support embedded objects or arrays of objects as queryable fields.

I hope this helps anyone who finds themselves in a similar situation.

Back to the drawing board!

1 Like

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