Adding fields to a model

I have developer mode enabled for my partitioned sync.
I added a few fields to my model in my Maui app and hoped these new fields would get synced back and appear in the collection in Atlas. The fields did not appear, and I tried various ways to force that to happen. I then tried terminated sync in Atlas and re-enabled it, but that did not help either. Eventually, something I did made the new fields appear.
Can anyone tell me the correct way to make this happen? My app is in its early stages, so I know I will be expanding various models as the app develops.
I now see there are 8 documents in the collection in Atlas. 4 with the old schema and 4 with the new schema. It appears that the app is correctly showing the 4 docs with the new schema. It would be good to know what is the best approach to changing a schema. If there were thousands of docs in the collection, it would not be great to duplicate all of them each time the schema is changed.

Hi. Can you elaborate on what you did you change your schema? When you update your schema from dev mode or in the UI we will perform another initial sync to resync down all changes (and new fields in existing documents)

I just added new fields to the C# model in the MAUI app. It eventually worked, as I said, but I wondered if there was a proper procedure to do this to avoid clearing data on the device etc.

I have to say, when sync works, it is very impressive. I had 2 devices side by side with the same person logged in on each. Changing data on one screen was updated on the other screen in about 1 second or less. It looked quite magical. This is making use of MVVM so I was not having to tap save.

I have a similar problem now. I realised that one of my properties in the MAUI C# model had been set to required when it shouldn’t have been so I removed the attribute. Now, whatever I do I get an exception

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

on this line

var realm = await Realm.GetInstanceAsync(syncConfig);

I terminated and restarted sync in App Services but that made no difference. I also uninstalled and reinstalled my mobile app (to clear data) but that made no difference.

The collection for the model that had the required attribute removed has yet to be synced back to Atlas. By that I mean the collection is empty in the database at the server.

I will try adding back the required attribute in the C# model to see if I can get it to work again. At present, when these kinds of problems happen, I don’t know how to fix them. In fact, I’ll try restarting Visual Studio because that has sometimes helped.

I’ve managed to get it to work again but the question remains, what is the correct procedure to change a model? I’m in dev mode making all schema changes in the MAUI app by changing the model. Currently, after any change, I have a long process of trial and error to make my mobile app work again. Deleting data for the app on the device, terminating sync and restarting, and deleting collections. I only try these things as a last resort to try to make it work again.