Filtered replication by AND'ing conditions


I’m working on an application that may require up to four conditions to be AND’ed together for client pull replications. But I don’t know if I can achive this using Sync Gateway, Couchbase Lite and Couchbase Server.

The Couchbase Server database may contain tens, or even hundreds, of “logical databases” that represent different customer sites. So the first condition would select one of these.

Then within each logical database, there may be up to three conditions that need to be AND’ed together to define the subset of documents to pull.

So as an example, a pull replication may have these conditions:
Site = ‘A’ AND Cond_1 = ‘B’ AND Cond_2 = ‘C’ AND Cond_3 = ‘D’

But I don’t know if I can achieve this with Sync Gateway as channels seem to be OR’ed together?

One possibility I thought of was to only use the first condition (Site = ‘A’) to pull the entire logical database, and then use filtering in the application for the other three conditions. Although this could work, it would result in a lot of unnecesaary documents being replicated from the logical database to the mobile device. And with up to several hundred logical databases, I assume each one would need a unique channel name - which would then have to be assigned to each user (unless I used roles instead)?

So is this a feasible use case for Sync Gateway?



How many different combinations of ANDed conditions will there be? Because you could assign each one of those a channel.


Thanks for your reply, Jens.

I’m currently working with a contracting company that gets around 10 new customer sites every year, and each site may require 50 - 200 combinations. On the other hand, a company that just uses the application internally may also have a few hundred combinations, but that number won’t change much over time.

The approach I’m thinking of using involves creating unique channel names, as you suggested, by concatenating the conditions. So in my example, the channel name would be A_B_C_D. As each condition is a document property that’s represented by an ID, hopefully I can generate the channel names by using a sync function.

But then I’d have to assign those channel names to appropriate users or roles. That’s a bit harder as two of the conditions (say C and D) are user-dependent. So each user would have a different set of channel names - and they could have hundreds or thousands of them.

So it probably is achievable, but I’m wondering if there’s a better way to do it?