How do I update Local Realm to match Atlas App Service Schema

I changed database collection name and updated a type name on database schema from “SubcategoryObject” to “CategoryObject”.

I also have a TransactionObject that has a property that was linked to the SubcategoryObject (which has now been renamed). I turned off sync on Atlas service app and turned it on later but I’m getting a sync error:

Error integrating bootstrap changesets: Failed to transform received changeset: Schema mismatch: Link property 'category' in class 'TransactionObject' points to class 'CategoryObject' on one side and to 'SubcategoryObject' on the other.

The Swift Realm Object has already been updated:

class TransactionObject: Object, ObjectKeyIdentifiable {
	@Persisted(primaryKey: true) var _id: ObjectId
	// ...
	@Persisted var category: CategoryObject?
	// ...
}

I’ve also incremented schemaVersion and provided a migration block but the migration block is not being called, I set a breakpoint and it’s not hitting the breakpoint.

What else do I need to do to update the Local Realm database to match the schema on the Atlas service app so that I can get sync working again.

Without seeing more of your models, I can’t say for sure what the issue is. I’m guessing it’s one of a few possible things:

  • You may have missed updating something in the App Services schemas.
  • You may have missed updating something in your Realm Swift object models.
  • This seems like an odd message for it, but it could also be that you have existing data in your linked Atlas collection that uses the old schema and can’t sync because you haven’t updated the documents in Atlas to match your new schema.

When you’re using Device Sync, you don’t need to “migrate” the realm file that is on a device because it’s not a “local” realm. It’s a synced realm. That’s why your migration block breakpoint isn’t being hit - a synced realm doesn’t call the migration block.

After changing the schemas, the realm file on device should experience a client reset and re-download a new version of the synced realm. The Realm object models in your Swift code need to be updated to match the App Services schema. That, plus handling a client reset, are the only things your Swift code needs to do.

I’d say double check your schemas in App Services and in your Realm object models and make sure you’ve updated any documents in your linked Atlas collection that use your old schema to match your new schema, and one of those things should fix the issue.

(Also, if any of these are fields or object types you’re syncing on in the Flexible Sync subscription in your Swift app code, make sure you’ve updated the subscription query.)

Thank you @Dachary_Carey this is very helpful and provides a lot of insight on how schema changes are handled with a synced realm. I will keep digging based on this info