Yes, I have quite a few documents that could be changed on the server and need to get sync.'ed to mobile. The user can even edit his/her documents on the server (and these changes need to get sync.'ed to the mobile.
I don’t save a “channel” on each document… I understand that was a way to do it in earlier versions. I just checked and there is a “channel” object in the meta data of the documents. So it must be the sync. gateway itself that uses the sync. function to calculate what channels to add to a particular document. That also explains why you have to take the database offline and do a
_resync whenever you have made changes to the sync. function that impacts channels.
Those documents that have no channels in their meta data do not sync to the mobile. I guess that could also be handled by the sync. gateway looking at the import filters (that I have been advised to use by @priya.rajagopal) when doing a resync.
I think that the requirement to update docs via the sync.gateway was a thing of the past (pre-version 2.x where I started). I just use the Java SDK to access the data directly in the cluster. There even isn’t yet a sync.gateway in my production environment as the app using the CBLites is under development…
So it sounds like the concept was easier to grasp earlier.
Basically, I don’t understand when the document ends up in e.g. my code above when there is a
userkey (can be on several types of documents)… Does this not happen both for documents being sync’ed TO the mobile (I’m setting the channel for ‘User’ and public documents to “!” - but for the ones belonging only to this user I set the channel for user and gives access)? When an update (or document) is received FROM mobile I guess that the
requireUser(,,,) is what allows it to update?
I had another look at the documentation and the only hint that the
doc object is FROM the mobile is the “This matches the JSON that was saved by the Couchbase Lite and replicated to Sync Gateway”.
So I guess if I just “accept” that the
doc is always the mobile version of a document and the
olddoc is always the server version of the document - then I can build my validation correctly - … although calculating the channels in the same function kind of reverses the perspective as we look at
doc to find out what channels to assign to it…
Thank you very much for your patience - and I’ll play a little around with the new repl. event!