Error: cannot get schema in kotlin to match device sync

I am unable to get my kotlin schema to match my atlas device sync schema no matter what I do.

I have copied the sync model directly out of atlas and it is still giving me the following error: [Logic][InvalidSchemaChange(2019)] Invalid schema change (UPLOAD): non-breaking schema change: adding schema for Realm table “items”, schema changes from clients are restricted when developer mode is disabled Logs:

My class: class items:

    RealmObject {
    @PrimaryKey
    var _id: ObjectId = ObjectId()
    var active: Boolean = false
    var basePrice: Decimal128 = Decimal128("0")
    var caseCost: Decimal128 = Decimal128("0")
    var caseCount: Long = 0
    var category: String = ""
    @FullText
    var department: String = ""
    var description: String = ""
    var ebtItem: Boolean = false
    var scaleItem: Boolean = false
    var tenant: String = ""
    var upc: String = ""
    var wicItem: Boolean = false
}

I have also tried:


class item : RealmObject {
    @PrimaryKey
    var _id: ObjectId = ObjectId()
    var active: Boolean = false
    var basePrice: Decimal128 = Decimal128("0")
    var caseCost: Decimal128 = Decimal128("0")
    var caseCount: Long = 0
    var category: String = ""
    var department: String = ""
    var description: String = ""
    var ebtItem: Boolean = false
    var scaleItem: Boolean = false
    var tenant: String = ""
    var upc: String = ""
    var wicItem: Boolean = false
}

The schema in device sync is:

{
  "title": "item",
  "properties": {
    "_id": {
      "bsonType": "objectId"
    },
    "active": {
      "bsonType": "bool"
    },
    "basePrice": {
      "bsonType": "decimal"
    },
    "caseCost": {
      "bsonType": "decimal"
    },
    "caseCount": {
      "bsonType": "long"
    },
    "category": {
      "bsonType": "string"
    },
    "department": {
      "bsonType": "string"
    },
    "description": {
      "bsonType": "string"
    },
    "ebtItem": {
      "bsonType": "bool"
    },
    "scaleItem": {
      "bsonType": "bool"
    },
    "tenant": {
      "bsonType": "string"
    },
    "upc": {
      "bsonType": "string"
    },
    "wicItem": {
      "bsonType": "bool"
    }
  },
  "required": [
    "_id",
    "active",
    "basePrice",
    "caseCost",
    "caseCount",
    "category",
    "department",
    "description",
    "ebtItem",
    "scaleItem",
    "tenant",
    "upc",
    "wicItem"
  ]
}

What can I do to use this device sync collection in Android?

Hi, can you send a link to your application in the App Services console? Alternatively I would just need the application id that is a part of the URL in order to look more closely.

https://realm.mongodb.com/groups/${GROUP_ID}/apps/${APP_ID}

Hi Tyler,

Thanks for the help.

Here is the link: App Services

Hi, I believe the issue is coming from the difference between item and items.

In the backend you have a schema on a collection called items but it has a "title": "item" which means that it will correlate to a Realm class named “item” not “items”.

Therefore, you should have 2 options:

  1. Change the title field in the schema page to be “items”
  2. Use “item” as the name of your realm object

Most of the errors in your application are:

ending session with error: non-breaking schema change: adding schema for Realm table "items", schema changes from clients are restricted when developer mode is disabled (ProtocolErrorCode=225)

This is the error you get when the backend has the schema as “item” but you are passing it a schema with the title of “items”

I see you tried using a realm object that has a title of “item” but I cant easily find in the logs what error you are getting when using that since all of the errors I have found are the one above.

Either way, I would suggest either:

  1. Using “item” and report back if/what the error is when doing that (I would expect that to work)
  2. Update the backend schema to just be “items” and deploy it as a breaking change (you are in development so there shouldn’t be an issue)
  3. Turn on developer mode which will just create the schema on the backend exactly as you are using it in Realm

Best,
Tyler

Hi Tyler,

I changed my model to reflect that:

import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.PrimaryKey
import org.mongodb.kbson.Decimal128
import org.mongodb.kbson.ObjectId

class item : RealmObject {
    @PrimaryKey
    var _id: ObjectId = ObjectId()
    var active: Boolean = false
    var basePrice: Decimal128 = Decimal128("0")
    var caseCost: Decimal128 = Decimal128("0")
    var caseCount: Long = 0
    var category: String = ""
    var department: String = ""
    var description: String = ""
    var ebtItem: Boolean = false
    var scaleItem: Boolean = false
    var tenant: String = ""
    var upc: String = ""
    var wicItem: Boolean = false
}

However the logs still show that it is trying to change the table items, is there somewhere else where I need to change that name?

Are you clearing the simulator when you do that? Realm is persistent, so if you open a realm with a table called items, and then you reopen it with a table called item, the realm now just has item and items.

Can you try from a completely fresh realm, and if the issue persists, send me a link to the request id in the logs of the error that occurs?

Hi,

Can you point me towards some docs on how to clear the simulator? I’m not really familiar with that concept and couldn’t find anything by searching the docs.

@Zach_Wright Even without device sync - you’ll want to familiarize yourself with how to clear data and build folders on iOS during development. You’ll be using them a lot.

Awesome, I’m developing for android right now but I will take a look as I’m sure the concepts are similar.