All,
I know that document order during sync is uncertain (that’s been commented on in this forum before). So I am wondering how people get around the following problem.
I have a container document that may be shared by multiple users. I do this by having a channel with the same ID as the container. Users have a list of channels they can access (containers), and whenever the user document is saved, the channels that user can access are updated. Here is the code from the sync function:
// update the user's channels from the list of containers they have access to
if (!isDelete() && doc.type == "User") {
var container_ids = Object.keys(doc.containers);
access(doc._id, container_ids);
}
The container/channel ID’s are cryptographically strong, so its hard for someone to guess a channel and give themselves access.
When a user is offline, they may create some containers and some documents that are members of the container (those docs have the same channel id as the container). The user document is updated with this new channel/container.
When the device reconnects to the internet, the various documents are synced (user, container, documents). Problem is that the user wont have access to the container/documents until the user record is saved causing the user’s channels to be updated, and that may be after the container/documents sync. So initially the user fails to sync those documents/containers. And it seems that even if the channels are changed later, the documents that were skipped before never resync, unless they get changed.
One way is to turn off my check for the channel:
if (doc.type == "Container" || doc.type == "Document") {
requireAccess(doc.channels);
}
I’m guessing that perhaps I don’t need this because the sync engine wont sync docs that dont belong to your allowed channels. However, to stop anyone attempting to insert docs via non-sync means - I thought it was safest.
Perhaps another way could be to force the sync engine to reassess the sync status of all documents? I can’t see a way to do that.
Just wondering if there is a strategy that others use here to manage being offline, and needing to make changes to channels at the same time as their documents?
Many thanks for any ideas you can provide.