Conrad
Conrad

Reputation: 53

Use cloudant/couchDB update handlers to write records into another database

I am using IBM cloudant's update handlers to add timestamp on document when it is created/updated. I am able to use the following function to add timestamp to the documents in the update handlers' database.

function(doc, req) {

if (!doc) {    
    doc = {_id: req.uuid};
}
var body = JSON.parse(req.body);
for (key in body){
    doc[key] = body[key];
}
doc.timestamp = + new Date();
return [doc, JSON.stringify(doc)];

}

However, I would like to keep all the history in another database (saying HISTORY database). How could I insert a document from current database's update handlers to another database? Thank you.

Upvotes: 0

Views: 153

Answers (1)

ptitzler
ptitzler

Reputation: 923

One potential solution might be to set up continuous replication and define the update handler on the target database. The replication source database would be your HISTORY database containing the original documents and the target database store the time-stamped documents.

Upvotes: 0

Related Questions