My setup for flexible sync in an iOS app, using RealmSwift (schema seems fine, it was created automatically by using development mode):
final class User: Object {
@Persisted var params: List<UserParam>
}
final class UserParam: EmbeddedObject {
@Persisted var key: UserParamKey
@Persisted var value: String
}
enum UserParamKey: Int, PersistableEnum {
case firstName, lastName, businessName [etc]
}
User schema:
{
"title": "User",
"type": "object",
"required": [
"_id",
"lastOnboardingStep"
],
"properties": {
"_id": {
"bsonType": "objectId"
},
"calendarId": {
"bsonType": "string"
},
"lastOnboardingStep": {
"bsonType": "long"
},
"ownerId": {
"bsonType": "string"
},
"params": {
"bsonType": "array",
"items": {
"title": "UserParam",
"type": "object",
"required": [
"key",
"value"
],
"properties": {
"key": {
"bsonType": "long"
},
"value": {
"bsonType": "string"
}
}
}
}
}
}
When I’m using a local Realm everything works fine. When I do anonymous login, I’m getting these errors:
{
"logs":[
{
"_id":"6465f6ed0a9d994f8d714314",
"co_id":"6465f6eb0a9d994f8d7142c9",
"type":"SYNC_SESSION_END",
"user_id":"6465f6ebeb4f073b5d5f2ca9",
"domain_id":"645915213a82d1d7fbafefca",
"app_id":"645915213a82d1d7fbafefc9",
"group_id":"64591410ffb83f492c3916c7",
"request_url":"/api/client/v2.0/app/billy-jgeoz/realm-sync",
"request_method":"GET",
"remote_ip_address":"5.14.130.67",
"started":"2023-05-18T09:59:09.083Z",
"completed":"2023-05-18T09:59:09.126Z",
"function_call_location":"DE-FF",
"function_call_provider_region":"aws-eu-central-1",
"error":"ending session with error: failed to generate history batches: error generating object modifications: error generating post image: image generator encountered error applying instruction to state: error applying instruction to object in table 'User' with primary key '6464e5cc20c418867833b418' at field path 'params.0': ArrayInsert.prior_size was 0 but built-up array was only of length 14 (ProtocolErrorCode=212)",
"error_code":"BadChangeset",
"messages":[
"Session was active for: 0s"
],
"platform":"unknown",
"platform_version":"Version 16.4 (Build 20E247)",
"sdk_name":"Realm Swift",
"sdk_version":"10.39.1",
"sync_query":{
"Settings":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"User":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"Appointment":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"Client":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"Invoice":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"RecurrenceStatus":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"Service":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")"
},
"sync_session_metrics":{
"uploads":2,
"downloads":4,
"downloaded_changesets":3,
"downloaded_changesets_size":920,
"changesets":2
}
},
{
"_id":"6465f6ed0a9d994f8d714313",
"co_id":"6465f6eb0a9d994f8d7142c9",
"type":"SYNC_CLIENT_WRITE",
"user_id":"6465f6ebeb4f073b5d5f2ca9",
"domain_id":"645915213a82d1d7fbafefca",
"app_id":"645915213a82d1d7fbafefc9",
"group_id":"64591410ffb83f492c3916c7",
"request_url":"/api/client/v2.0/app/billy-jgeoz/realm-sync",
"request_method":"GET",
"remote_ip_address":"5.14.130.67",
"started":"2023-05-18T09:59:09.083Z",
"completed":"2023-05-18T09:59:09.126Z",
"function_call_location":"DE-FF",
"function_call_provider_region":"aws-eu-central-1",
"error":"failed to generate history batches: error generating object modifications: error generating post image: image generator encountered error applying instruction to state: error applying instruction to object in table 'User' with primary key '6464e5cc20c418867833b418' at field path 'params.0': ArrayInsert.prior_size was 0 but built-up array was only of length 14 (ProtocolErrorCode=212)",
"error_code":"BadChangeset",
"messages":[
"Upload message contains 1 changesets (total size 1.4 kB) to be integrated"
],
"platform":"unknown",
"platform_version":"Version 16.4 (Build 20E247)",
"sdk_name":"Realm Swift",
"sdk_version":"10.39.1",
"sync_query":{
"Service":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"Settings":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"User":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"Appointment":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"Client":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"Invoice":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")",
"RecurrenceStatus":"(ownerId == \"6465f6ebeb4f073b5d5f2ca9\")"
},
"sync_write_summary":{
"Service":{
"inserted":[
"6464ce7583f82645c6f9bc2d"
]
},
"Settings":{
"inserted":[
"6464e5cc20c418867833b419"
]
},
"User":{
"inserted":[
"6464e5cc20c418867833b418"
]
}
}
}
]
}
It should be possible to have a list of embedded objects, right?