Flexible sync error while syncing Dictionaries

Hey there! I’m trying to sync data from the atlas.

I’m using Unity 2021.3.16 and RealmSDK version 10.20.0

Sample object in the collection:

bar Object
    a: "aaa"
    b: "bbb"
    c: "ccc"

This data was written by Python MongoDB side as a dictionary.

Here’s my schema:

{
  "title": "Foo",
  "properties": {
    "_id": { "bsonType": "string" },
    "bar": {
      "bsonType": "object",
      "additionalProperties": { "bsonType": "string" }
    }
}

and c# class:

public class Foo : RealmObject
{
    [MapTo("_id")]
    [PrimaryKey]
    [Required]
    public string Id { get; set; }

    [MapTo("bar")]
    [Required]
    public IDictionary<string, string> Bar { get; }
}

Here are some problems I collided with:

  1. Partitional syncing can’t find any objects, realm.All<Foo>() returns a 0 length collection.
  2. realm.WriteCopy() throws an exception: Incompatible property: class_Foo::bar
  3. Flexible sync does not work at all. I could not manage to get it to work.

I also tried to use RealmDictionary<string> but the result was the same.

Thanks!

Hi,

Sorry to hear things aren’t going great for you thus far. We are looking to surface some of these schema compatibility issues a bit better in the coming months. A few thoughts off the bat:

  1. Your JSON Schema looks correct to me
  2. Your Realm Model doesnt match up with your JSON Schema. I am surprised sync is even running for you. I suspect we rejecting the sync connection immediately. The reasons are that the Realm Scheme has _id as a required field but the JSON schema has it optional (missing the “required” tag). Also, we only support “non-required” dictionaries right now.
  3. I’m not sure why your Partition Sync app is not returning any results. Can you confirm:
  1. Why are you using WriteCopy()? That is a very specific method to generate state realms and I suspect you might not be trying to. You likely are just looking for Write()

  2. Can you provide more details around what isnt working with Flexible Sync?

My best advice for you now would be to:

  1. Terminate sync
  2. Remove all schemas from the App Services UI
  3. Enable sync and turn “dev mode on”
  4. Connect the client to the app and it should automatically generate the JSON Schema given your Realm Object Models if they are valid.

If that doesn’t work, please let me know and perhaps provide your app_id (can be the URL in your App Services page) and I can try to look at what might be going wrong.

Best,
Tyler

Hi Tyler!
I’ve joined from another account.

I made a document about all steps I did to show you my progress with this issue. I also made a more complicated schema to understand how to deal with embedded objects.

I also made a sample project from another Gmail, so you can easily play with it. Here’s the link:
https://cloud.mongodb.com/v2/6400fd7092a24557972a3b45#/clusters

Thanks!