I have a server-side filter (javascript: function(doc, req)
) setup which checks the document type and returns true or false for replication status. I have a scenario where I have to check content of a document say DocumentA in order to decide whether to replicate DocumentB. But there is no sequence in which the doc
are passed to the javascript. e.g. DocumentB can arrive for syncing before DocumentA, at this point I don't know what to return
without the knowledge of DocumentA. How can I achieve this?
Asked
Active
Viewed 288 times
0

Mark Glasgow
- 529
- 2
- 9

Nagesh
- 167
- 1
- 2
- 11
-
Where are you configuring this server-side filter? As far as I was aware, sync gateway doesn't have any ability to write custom replication filters server side. It only supports sync_gateway/bychannel and _doc_ids. See filter param here: http://developer.couchbase.com/documentation/mobile/current/develop/references/sync-gateway/rest-api/database-public/get-changes/index.html – Mark Glasgow Jul 28 '16 at 06:02
-
Further, Couchbase lite only supports client-side filters or the channels & doc ids. see: http://developer.couchbase.com/documentation/mobile/current/develop/references/couchbase-lite/couchbase-lite/replication/replication/index.html – Mark Glasgow Jul 28 '16 at 06:05
-
I'm using filtered replication not sync_gateway. Filters functions is in design document – Nagesh Jul 28 '16 at 07:33
-
Does that mean you are replicating from Couchdb or something else, rather than couchbase? I was under the impression the only way to replicate couchbase lite with couchbase was sync_gateway. – Mark Glasgow Jul 29 '16 at 03:36
-
Can you clarify, as per @MarkGlasgow's questions? You've tagged this for Couchbase Lite and Sync Gateway. The docs are clear on what your options are for filtering when going from CBL->SG->Couchbase server. This isn't about what's possible on the server-side only, but how it integrates with CBL. – Hod Jul 29 '16 at 23:45
1 Answers
0
First, about filtering. You can filter by channel and document ID. Here's the relevant section from the docs (as of v1.2):
Replications can have filters that restrict what documents they'll transfer. This can be useful to limit the amount of a large remote database that's downloaded to a device, or to keep some local documents private. A special type of filter used with the Couchbase Sync Gateway is the set of channels that a pull replication will download from. It's also possible to limit a replication to an explicit set of document IDs.
Based on your description, one solution might be to set up a channel for the particular doc type (your DocumentA), and another for your other docs. Then, use one-shot replications to guarantee ordering.

Hod
- 2,236
- 1
- 14
- 22