Reset sync session after user custom data update


I would like to know if I can “restart” the a sync session after user custom data has been updated.

Currently I’m getting a compensating write error because changes from user custom data wasn’t reflected on the sync session.

I have an example of my use case in the mongodb device sync permissions guide, which can be found in this link.

The problem:

Considering the example above, a user custom data has the field “subscribedTo” which is an array of ids. This field is used in a permission role, it checks if the document field is inside the “subscribedTo” array.

Everything works as the guide shows, the problem appear when “subscribedTo” field is updated. At that point, I’m calling user.refreshCustomData() to get the newest addition, but even after that, if I try to insert a document, I get this compensating write error “Reporting compensating write for client version 3312 in server version 3635: Client attempted a write that is outside of permissions or query filters; it has been reverted”.

The guide says that when the “subscribedTo” field is updated, the changes don’t take affect until current session is closed and new session is started.

My question:

I’m wondering if I can restart the current session without closing my realm connection, since I would like to keep my sync subscriptions intact.

Thank you!

I found a “workaround” for the issue. I’m getting the current sync session and calling “pause()” and “resume()” one right after the other, to force the sync session to stop and start again. Is this the best practice for this? Or is there a better solution for this?

Currently, the sync server caches custom user data for the duration of the session. So, as you’ve found, pausing/resuming is a good way to restart the session, resulting in updated permissions. This is a good solution for this problem


Sounds good, thanks for the reply. I would still suggest to provide and example of how to handle that in the mentioned guide, or some other part of the documentation. Thanks again.

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