James Simm
James Simm

Reputation: 1579

Couchbase Multi-Key Get with Composite Keys

I've got a problem with querying a Map/Reduce view in Couchbase for specific keys.

The view maps some documents in Couchbase, emitting a composite key and a value and calls the built-in _stats reduce function. I'm grouping on the 2nd part of the key (group=true&group_level=2) and the results are exactly what I want.

The issue I've got is I need to find the "reduce" result for specific document IDs which aren't necessarily sequential, so I can't use startkey and endkey.

For example, looking up the results for document IDs 2, 5, 8, 18, using &startkey=[2, null]&endkey=[18,"\u0fff"] could potentially return results for documents with IDs 3, 4, 6, 7, 9-17.

I'm looking at using the keys=[] parameter to specify the document IDs to look for, but can't work out how to do this when using a composite key.

Is this possible, and if so, how do I do it?

Upvotes: 3

Views: 452

Answers (1)

James Simm
James Simm

Reputation: 1579

Turns out I was misunderstanding how this should work, after some reading I've made split different bits of my query out into separate views and it now works as I expect it to.

The reduce view now has a single key, rather than a composite key, which means I can query it via the keys parameter.

Upvotes: 2

Related Questions