Custom Conflict Resolution implementation

From https://docs.mongodb.com/realm/sync/conflict-resolution/#custom-conflict-resolution, it doesn’t explicitly states the implementation details of handling custom conflict resolution.

I imagine this is how it would need to work but can someone validate my understanding?

Suppose we have an object with a status flag (status = high, medium, low) and say we always want status = high to win.

I assume that

we need to put this object into a list, sync it back, and when the list gets synced back to Atlas, trigger will need to be initiated, call the function, resolve the conflict based on custom logic (ie. loop thru the list and check which status = high), and then delete the rest of the items in the list, then persist the actual record it back to Atlas, such that the resolution results are reflected back on the connected devices?

Can someone shed some light around this and validate my understanding? Thanks!

Welcome to the forums!

We don’t go into too much detail on custom conflict resolution because it will vary depending on the application and the regular conflict resolution works for most cases. That said I think the workflow that you outlined should work.

One thing to consider is that your client apps will likely also see the intermediate states, i.e. they’ll see the status=high object get added to the list and then a little bit later see the other objects deleted as a result of the trigger update. This may or may not matter too much for your use case but be prepared to handle it if it comes up.

2 Likes