Changes cannot be made in additive-only schema mode

Hi,

I am developing a mobile app using React Native and MongoDB Realm. For backend sync using MongoDB atlas.

When schema is changed at client side and synced to atlas server, getting the following error:

“The following changes cannot be made in additive-only schema mode:
Property ‘Users.FirstName’ has been made optional.”

Schema is as follows:

export const Users = {

name: ‘Users',
primaryKey: '_id',
properties: {
	_id: "objectId",
	_partition: "string",
	FirstName: 'string?',
            LastName: 'string?',
	MobileNumber: 'int',
}

};

In a production application, when we made some changes in the schema like “FirstName” field is required previously & later, we make it optional, and we have 10000 of users using the app, then how can we handle this situation.

Regards

1 Like

Hi Vishnu,

Changing an existing property to optional is an example of a destructive change and you would usually have to manually update your server side schema to match the destructive change in your client.

The following are all considered destructive changes:

  • Changing a property’s type but keeping the same name
  • Changing a primary key
  • Changing a property from optional to required (or vice-versa)

What does your schema look like in the Realm UI ?
Please include the required fields as well. If you have FirstName under the “required” section, you would have to remove it from there to match your client schema as being Optional.

Regards
Manny

1 Like