jbaylina
jbaylina

Reputation: 4718

Is it possible to create a view of a view in couchbase?

I would like to create a map/reduce operation over the results of a view. Is it possible to do it in couchbase?

Or what's the same, how do you translate a HAVING SQL command to couchbase.

As an example, in the "by_location" view in the beer_sample bucket, I would like to create a view with the key [count, country] so I can ask which countries have 1 brewery or have more than 4 breweries.

Upvotes: 0

Views: 121

Answers (2)

Austin Gonyou
Austin Gonyou

Reputation: 252

I have thought on this very point a few times. So I see a scenario where by the view query could output some meaningful information without a reduction function but still enable a fairly smaller subset of the data. This could then be used as input to a new bucket by an external process which both queries the original view, and then sets new keys into a bucket with the view results. A view could be built on what those keys are to derive additional view information. Alternatively, one could just create a custom reduction function.

One post on this subject is here:

Couchbase custom reduce function

Upvotes: 0

John Zablocki
John Zablocki

Reputation: 1592

With Couchbase map reduce, the count would have to come from the reduce function and therefore couldn't be part of the key of the index. Since only keys may be queried against, it isn't possible to emulate the having directly through the view.

If you have nested documents (i.e., an array of breweries within a country), you could achieve something close to what you want. But again, with separate documents, the count has to come from the reduce.

Upvotes: 1

Related Questions