I’m trying to implement Realm flexible sync, which works great when having a fixed schema. However, in my case, a part of the document is schema-less, and the exact structure is unpredictable and can differ per document instance.
I tried to include an object property with “additionalProperties: true” to allow varying content (free structure), but this only works when putting primitive properties inside the object. When adding complex property types, like nested objects, the documents are being ignored (not read/synced) when using device sync.
The schema looks like this:
{
"title": "AgendaItem",
"bsonType": "object",
"required": ["_id", "tenant", "date"],
"properties": {
"_id": { "bsonType": "objectId" },
"tenant": { "bsonType": "objectId" },
"date": { "bsonType": "string" },
"attributes": {
"bsonType": "object",
"additionalProperties": true
}
}
}
This document works (at least it is being read by the client):
{
"_id": "xyz",
"tenant": "t1",
"date": "2020-01-01",
"attributes": {
"foo": "bar"
}
}
But this does not work (the document is not being read when starting sync):
{
"_id": "xyz",
"tenant": "t1",
"date": "2020-01-01",
"attributes": {
"foo": {
"bar": "baz"
}
}
}
Is it expected behaviour that complex structures are not supported? Is there any other way to accomplish a flexible (partial) document structure? Thanks!