MongoDB Realm App tires to sync entity suppose to be used locally

I have a Realm object entity that is only used inside a local Realm. When I start the app and the Realm App got instantiated, Realm throws an error saying that the object entity has no _id field since it is required for a synchronized Realm.

Realm seems to scan all entities defined in the project and try to validate their schema.

Any I missing anything? How can I tell App which entity is for local OR I have to sync all entities I used to MongoDB Realm to use them?

// X/RealmProvider.swift:25: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=1 "Schema validation failed due to the following errors:
// - There must be a primary key property named '_id' on a synchronized Realm but none was found for type 'DCData'" UserInfo={NSLocalizedDescription=Schema validation failed due to the following errors:
// - There must be a primary key property named '_id' on a synchronized Realm but none was found for type 'DCWordData', Error Code=1}

Hi @Dududu,

When you open the realm, you automatically define which kind it will be, i.e. local or synched. You can’t have objects in the same realm that are synched, and others that are not, so you’ll have to open two separate realms.

To instruct the SDK to add only some classes to a realm, and not others, you can use the objectTypes array of the configuration object you’ll pass to open the realm itself: by default, all RealmObject classes that the SDK finds in your code will be considered part of an opened realm, if you want to limit which ones are handled in a specific one, you have to list them explicitly.

1 Like

Thank you so much Paolo! That answers my questions.

I did not understand why the new schema needs to be on the Cloud because it is only used on the client side. Secondly, I do not understand how does the Realm app knows I have a new Object Model.

The missing type declaration inside the configuration is what I missed!!!

Thanks again!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.