Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CouchDb: How to delete documents older > 6 month?

Tags:

shell

couchdb

I have the problem that I like to "automagically" delete documents in my couch, which are at least 6 month old. My CouchDb instance runs on a linux server, is there any way to achieve this quite simple (like writing a simple 2-line shell script) ?

like image 893
Robert Heine Avatar asked Jun 20 '11 12:06

Robert Heine


1 Answers

You can write an update function in couchdb that deletes a doc on certain criteria ( you can use params while calling the function) : http://wiki.apache.org/couchdb/Document_Update_Handlers#Creating_an_Update_Handler

(look at "in-place" and imagine setting "_delete:true").

something like

"deletefunc":
...
if(doc.created_at<req.query.mindate) {
  doc._deleted:true;
  return [doc, "deleted"]
}

and calling ...db/_design/updatefuncdesigndoc/_update/deletefunc/dok_id_x?mindate=20110816

The only work is: calling each doc in a database explicit with this function (calling _all_docs or _changes first)

like image 190
okurow Avatar answered Sep 25 '22 22:09

okurow