0

I am trying to delete docs from couchdb by using

function(doc) {
    var startdate= new Date(doc.Date);
    var enddate= new Date("July 12, 2013 11:13:00");
    if(startdate < enddate){
        emit([startdate, enddate], doc._id);
        doc.remove();
    }
}

I am getting the results, but not able to delete them and yes I have used this code in the temp view of the database

railsman
  • 132
  • 2
  • 14
  • possible duplicate of [How can I delete multiple documents in CouchDB?](http://stackoverflow.com/questions/10404178/how-can-i-delete-multiple-documents-in-couchdb) – sebster Aug 11 '14 at 14:43

1 Answers1

2

What you're trying to do is bulk delete. It cannot be done from a view, like you tried it. I recommend you read the CouchDB documentation first, to see how normal CRUD operations are made.

If you want to skip that step(not recommended but we're all in a hurry sometimes) then check this SO question: How can I delete multiple documents in CouchDB?. It's the same problem as yours.

I'm sorry to break it for you, but there's no easy answer to this problem. But I'll try to outline the logic required for this task:

  1. Retreive the documents you wish to "delete", based on your view logic
  2. Do a bulk update on your documents for the field _delete and set it to true(_delete=true) http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
  3. Read some more on what deleting means for CouchDB: http://n.exts.ch/2012/11/baleting AND http://docs.couchdb.org/en/latest/api/database/misc.html

Good luck!

Community
  • 1
  • 1
sebster
  • 1,322
  • 2
  • 18
  • 29