You could use N1QL embedded in an event handler, and store the result in a bucket. You can then either refresh the aggregate periodically using either timers.
You could create a map function which emits client and user and reduce function _count.
Then call the view with group_level=2 and start key as [client, null] and end key as [client, “\uffff”] and count the number of row returned. This will be the number of distinct user for that client for startkey[0].
Map:
function (doc, meta) {
emit([doc.client, doc.user]);
}
reduce: _count
Query:
Querying for distinct user for client “a”.
stale=false&inclusive_end=true&full_set=true&group_level=2&startkey=%5B"a"%2C%20null%5D&endkey=%5B"a"%2C%20"%5Cu0fff"%5D
Result:
{“rows”:[
{“key”:[“a”,“Value1”],“value”:100},
{“key”:[“a”,“Value2”],“value”:100}
]
}
counting the number of rows gives the number of distinct user for client “a”.
@jeelan.poola is there any road-map reference? Can you tell me then it is available on CE? @Siri as eventing is not available in community edition , is there any alternative way ? @Siri Is eventing eventual consist? assume in function we increase 3 counter , what happens when first counter increased and when increasing second we have a node failure?
We don’t have a firm date unfortunately. As Eventing is considered a developer feature, it is a candidate for inclusion to CE, but I don’t know the scope or timing of it, sorry.
Regarding consistency - eventing sees mutations after they have occurred. So there is a time lag between mutation and handler running.
Regarding counters - you shouldn’t count mutations because mutations are de-duplicated. When you create a handler, it sees all documents (“everything”) and if a document was overwritten multiple times, it will only see the newest few versions of the given document will be seen by the handler. So you can’t rely on counting mutations even regardless of node failure.
Regarding Node failure - eventing engine checkpoints the sequence number up to which it has processed regularly. If there is a node failure, a new node takes over from the last checkpoint. This means that there can be duplicate processing within the checkpoint window but not missed processing. The checkpoint window size is configurable as an advanced setting.
We do have features to address some of above to make Eventing more comparable with View capability over time, but as those are not on a scheduled release yet, I won’t go into the details.
It seems to me that if @AnkitPrabhu can refine his suggestion, Views may work better for your use case.