You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by N/A N/A <pr...@yahoo.com> on 2011/11/03 14:14:29 UTC

couchdb: function eval on insert, update...

Hi,

Any plans to implement doc features, like expression evaluation on insert or update in CouchDB? For example:
POST:
{
"test1": "1",
"test2": "2",
"test3": function(doc) { 
var res = doc.test1 + doc.test2 
return res;
/* or maybe even                if (doc["test2"]) { 
doc["test4"]();
} else {
... more stuff...
}
*/
    }
"test4": function(doc_or_maybe_something_else) { ... }
}

result in couchdb:
{
"test1": "1",
"test2": "2",
"test3": "3"
// ..etc.
}


Regards

Re: couchdb: function eval on insert, update...

Posted by Nils Breunese <N....@vpro.nl>.
N/A N/A wrote:

> Yep. Sometimes it is useful. But i think not in this case, because insert/update already happened. So i am doing another PUT/POST to update the document.
> I talk about document processing with server side logic before insert.

AFAIK document update handlers run before the document is created/updated, so I guess it would just work for your use case.

> For example i want to know which document is last in my DB based on some criteria. How to achieve that ? My _view is giving me all records with doc.name = "test", but which of those "test" documents is last? I can use date ofc. But using date as criteria is dangerous since date is outside server logic. Something/someone can change it. So last documents will not be last.

You could use a document update handler to have the server set a last modified date property on your documents. You could also maybe just query the _changes feed for a database: /<database>/_changes?limit=1

Nils.
------------------------------------------------------------------------
 VPRO   www.vpro.nl
------------------------------------------------------------------------

Re: couchdb: function eval on insert, update...

Posted by N/A N/A <pr...@yahoo.com>.
algo utc_random will do the job for the uuid problem.

regards


________________________________
From: N/A N/A <pr...@yahoo.com>
To: Nils Breunese <N....@vpro.nl>; "user@couchdb.apache.org" <us...@couchdb.apache.org>
Sent: Thursday, November 3, 2011 4:25 PM
Subject: Re: couchdb: function eval on insert, update...

Yep. Sometimes it is useful. But i think not in this case, because insert/update already happened. So i am doing another PUT/POST to update the document. 
I talk about document processing with server side logic before insert.

For example i want to know which document is last in my DB based on some criteria. How to achieve that ? My _view is giving me all records with doc.name = "test", but which of those "test" documents is last? I can use date ofc. But using date as criteria is dangerous since date is outside server logic. Something/someone can change it. So last documents will not be last.


________________________________
From: Nils Breunese <N....@vpro.nl>
To: "user@couchdb.apache.org" <us...@couchdb.apache.org>; N/A N/A <pr...@yahoo.com>
Sent: Thursday, November 3, 2011 3:59 PM
Subject: Re: couchdb: function eval on insert, update...

N/A N/A wrote:

> Any plans to implement doc features, like expression evaluation on insert or update in CouchDB? For example:
> POST:
> {
> "test1": "1",
> "test2": "2",
> "test3": function(doc) {
> var res = doc.test1 + doc.test2
> return res;
> /* or maybe even                if (doc["test2"]) {
> doc["test4"]();
> } else {
> ... more stuff...
> }
> */
>     }
> "test4": function(doc_or_maybe_something_else) { ... }
> }
>
> result in couchdb:
> {
> "test1": "1",
> "test2": "2",
> "test3": "3"
> // ..etc.
> }

Document update handlers [0] can be used to invoke server-side logic to create or update a document. Maybe you can use this to solve your use case?

Nils

[0] http://wiki.apache.org/couchdb/Document_Update_Handlers
------------------------------------------------------------------------
VPRO  www.vpro.nl
------------------------------------------------------------------------

Re: couchdb: function eval on insert, update...

Posted by N/A N/A <pr...@yahoo.com>.
Yep. Sometimes it is useful. But i think not in this case, because insert/update already happened. So i am doing another PUT/POST to update the document. 
I talk about document processing with server side logic before insert.

For example i want to know which document is last in my DB based on some criteria. How to achieve that ? My _view is giving me all records with doc.name = "test", but which of those "test" documents is last? I can use date ofc. But using date as criteria is dangerous since date is outside server logic. Something/someone can change it. So last documents will not be last.


________________________________
From: Nils Breunese <N....@vpro.nl>
To: "user@couchdb.apache.org" <us...@couchdb.apache.org>; N/A N/A <pr...@yahoo.com>
Sent: Thursday, November 3, 2011 3:59 PM
Subject: Re: couchdb: function eval on insert, update...

N/A N/A wrote:

> Any plans to implement doc features, like expression evaluation on insert or update in CouchDB? For example:
> POST:
> {
> "test1": "1",
> "test2": "2",
> "test3": function(doc) {
> var res = doc.test1 + doc.test2
> return res;
> /* or maybe even                if (doc["test2"]) {
> doc["test4"]();
> } else {
> ... more stuff...
> }
> */
>     }
> "test4": function(doc_or_maybe_something_else) { ... }
> }
>
> result in couchdb:
> {
> "test1": "1",
> "test2": "2",
> "test3": "3"
> // ..etc.
> }

Document update handlers [0] can be used to invoke server-side logic to create or update a document. Maybe you can use this to solve your use case?

Nils

[0] http://wiki.apache.org/couchdb/Document_Update_Handlers
------------------------------------------------------------------------
VPRO  www.vpro.nl
------------------------------------------------------------------------

Re: couchdb: function eval on insert, update...

Posted by Nils Breunese <N....@vpro.nl>.
N/A N/A wrote:

> Any plans to implement doc features, like expression evaluation on insert or update in CouchDB? For example:
> POST:
> {
> "test1": "1",
> "test2": "2",
> "test3": function(doc) {
> var res = doc.test1 + doc.test2
> return res;
> /* or maybe even                if (doc["test2"]) {
> doc["test4"]();
> } else {
> ... more stuff...
> }
> */
>     }
> "test4": function(doc_or_maybe_something_else) { ... }
> }
>
> result in couchdb:
> {
> "test1": "1",
> "test2": "2",
> "test3": "3"
> // ..etc.
> }

Document update handlers [0] can be used to invoke server-side logic to create or update a document. Maybe you can use this to solve your use case?

Nils

[0] http://wiki.apache.org/couchdb/Document_Update_Handlers
------------------------------------------------------------------------
 VPRO   www.vpro.nl
------------------------------------------------------------------------