4

I have got questions about views in couchdb At the moment, I have a number of views (e.g. view_A, view_B.... view_Z), for each view they contains same range of keys but with different values. ie:

view_A = {"key":"key_1", "value":10}, {"key":"key_2", "value":100}
view_B = {"key":"key_1", "value":5}, {"key":"key_2", "value":2}
view_C = {"key":"key_1", "value":1}, {"key":"key_2", "value":2}

I am expecting to have a view to represent values in view_A divided by values in view_B =>

view_A_over_B = {"key":"key_1", "value":2}, {"key":"key_2", "value":50}

A view to represent values in view_C times values in view_B =>

view_C_times_B = {"key":"key_1", "value":5}, {"key":"key_2", "value":4}

Would this be possible to have a map/reduce function which is calling the views and do the calculation as mentioned like above?

3 Answers 3

2

Views in CouchDB can only access the current document being processed and cannot access other documents, or data from other views. So, unfortunately, it is not possible using views in CouchDB to build the functionality you want.

As it's not clear how you're building the views, it may be possible to use List functions instead of views to build the results you need. List functions are more capable, but you're then responsible for outputting the results (as HTML, Json, etc.).

Sign up to request clarification or add additional context in comments.

Comments

1

View function run just once during document save.

You can define javascript functions that calculate desired numbers, than include the following in your views:

view_A:

...
emit(doc._id, funcA(doc));
...

view_B:

...
emit(doc._id, funcB(doc));
...

view_C:

...
emit(doc._id, funcC(doc));
...

view_A_over_B:

...
emit(doc._id, funcA(doc)/funcB(doc));
...

view_C_times_B:

...
emit(doc._id, funcC(doc)*funcB(doc));
...

You can use CommonJS Modules to define funcA, funcB and funcC. Or use obsolete macro.

Comments

1

There was already mentioned that it's not possible to use view against other views, maximum you may apply some list function to specific view (with cost of full scan processing complexity), but still you may look at third-party tools like Couch-Incarnate for chained views support. Also, Cloudant has support for chained views.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.