couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From J Chris Anderson <>
Subject Re: question on CouchDB views: how to use a query sting (formula) in the view
Date Mon, 26 Jul 2010 18:58:27 GMT

On Jul 26, 2010, at 11:23 AM, Fink Mark wrote:

> Hi there,
> I am using CouchDB for some time now and now I am stuck with the following
> question.
> Lets say I store some values from some Physics experiments in couchdb:
> ID   x1   x2
> 1     1     1.1
> 2     2     1.2
> 3     3     1.3
> 4     4     1.4
> ...
> Now I want to do some calculations within couchdb (NOT on the client side).
> Lets say I want to apply some formulas:
> y1 = 1*x1 + 0.5*x2*x2
> y2 = 1/3*x1 + 0.7*x2*x2*x2
> ...
> I am thinking about passing the formula as a parameter to the view. Is this
> possible without using eval and does the caching still work like if I apply
> the same formula again it is faster? Maybe there is a sample available?
> For a RDBMS I would probably do something like that:
> select (1*x1 + 0.5*x2*x2) as y1 from experiments;
> Please do not tell me that I have to use a different view for each formula
> because this is not possible besides it is possible to create new views
> dynamically when needed.

if you have a list of needed formulas ahead of time you could run them each in the view and
emit them under keys, so for each doc you can look up by key, the forumula you'd like.

so keys would be like emit([doc._id, formul_name], formula_value)

I'm thinking you don't want to do this.

Instead you want to apply the formula at runtime (on the server)

In this case you should use a _show function. Here's some info about them:


> Regards
> Mark

View raw message