Not able to sync data from local to atlas collection

I’m using Realm in react-native to make offline first application. This is my realm collection schema -

{
  "title": "LibraryNote",
  "properties": {
    "_id": {
      "bsonType": "objectId"
    },
    "_syncPartition": {
      "bsonType": "string"
    },
    "title": {
      "bsonType": "string"
    },
    "description": {
      "bsonType": "string"
    },
    "subject": {
      "bsonType": "string"
    },
    "tags": {
      "bsonType": "array",
      "items": {
        "bsonType": "string"
      }
    },
    "pages": {
      "bsonType": "array",
      "items": {
        "title": "NotesPage",
        "bsonType": "object",
        "properties": {
          "type": {
            "bsonType": "string"
          },
          "data": {
            "bsonType": "object",
            "additionalProperties": {
              "bsonType": "string"
            }
          }
        }
      }
    },
    "createdBy": {
      "bsonType": "string"
    }
  }
}

On the reat-native side, I’m using following schema to open realm -

   static NotesPage = {
        name: "NotesPage",
        embedded: true,
        properties: {
            type: "string",
            data: "{}"
        }
    }

    static schema = {
        name: "LibraryNote",
        properties: {
            _id: "objectId?",
            _syncPartition: "string?",
            createdBy: "string?",
            title: "string?",
            description: "string?",
            subject: "string?",
            tags: "string[]",
            pages: { type: "list", objectType: "NotesPage" }
        },
        primaryKey: "_id"
    };

The objects are not getting synced with the Atlas collection. The creation of objects locally is working without any errors. If I remove the “pages” attribute from the entire schema, the syncing starts working. So it seems like there is issue with the pages schema but I’m not able to identify it.

Pages attribute is supposed to be of this structure -

[{
        "type": "COVER_PAGE",
        "data": {
            "title": "Some title",
            "subtitle": "Some subtitle"
        }
    }, {
        "type": "LIST_PAGE",
        "data": {
            "title": "Location",
            "description":  "Some random description" 
                
        }
    }]

It is an array of objects. Each object contains type and data field. Type field is a string while data field is a dictionary.

Any help with this issue will be highly appreciated.

1 Like