1

I have four channels in my application: A, B, C, D. Some application users are only interested in documents contained in both channels A and B only. Also can be expressed as: A ∩ B. Others may be interested in a different combination like: A ∩ B ∩ D.

UPDATE

I don't think the following will work anyway

What has been suggested so far is that I can create a new channel (like A_B and A_B_D) for each combination and then tag the documents that meet the intersection criteria accordingly. But you can see how this could easily get out of hand since with just 4 channels, you end up with 15 combinations (11 extra channels).

Is there a way to do this with channels or perhaps some other feature I have missed in Couchbase?

janakagamini
  • 237
  • 3
  • 11
  • Why doesn't it work? Also, 15 channels aren't a big problem. If you have more than 4 criteria, you don't need all combinations, but only those actually requested by some users. It's a quite common scenario to have a channel per user, so this shouldn't be a problem. – TAM Apr 16 '16 at 14:02

1 Answers1

0

The assignment of channels to a document is done via the sync function. So a document is not "contained" in a channel, but it may have attributes from which the channels to which it is routed can be derived. Only in the simplest default case, the document's channel attribute will route it to the channel having that value of that attribute.

So what you intend can be achieved by putting statements like

if (doc.areas.includes("A") && doc.areas.includes("B") {
   channel("AB");
}

into the sync function. (I renamed the channels attribute to areas to make clear to the reader of the program that these are not the actual channels, but that channels are only derived from combinations of them.)

TAM
  • 1,731
  • 13
  • 18