incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Dingwall <>
Subject Re: compare two documents and update
Date Mon, 03 Mar 2014 07:53:57 GMT
Asoh Frank wrote:
> I am new to non relational databases and couchdb as a whole. I want to ask if there is
any flexible possibility of comparing an existing document in the couchdb database with another
document(json file) not in the database then the difference between them will be uploaded(updated)
to the current existing document ?
This could be achieved with a design document update function. Something 

function(doc, req) {
     // doc is the destination doc id
     // req.body contains the text representation of the JSON document 
to merge
     // e.g. curl -X POST 
http://mycouch:5984/mydb/_design/merger/_update/merge/id-of-dest-doc -H 
"Content-Type: application/json" -d @doc-to-merge.json
     var jbody = JSON.parse(req.body);

     try {
         // my code to merge jbody on to doc
     catch(e) {
         return([null, "my error explanation"]);

     return([doc, "OK"]);


View raw message