1

So I've been trying to move data from one database to another. I've already move them but I need to clear the documents which I've already moved from the old database. I've been using ektorp's execute bulk to perform bulk operations. But for some reason I keep getting document update conflict when I try to delete bulk by inserting _deleted. I might be doing it wrong, here is what I did.

  1. Fetch by bulk with include docs. (For some reason, this doesn't work with just id and rev.)
  2. Then include the _deleted field to each document.
  3. Post using executebulk.

It works for some documents but keeps getting document update conflict for some documents.

Any solution/suggestions please..

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Vebito
  • 154
  • 1
  • 10

2 Answers2

2

This is the preferred way of deleting docs in bulk:

List<Object> bulkDocs = ...
MyClass toBeDeleted = ...

bulkDocs.add(BulkDeleteDocument.of(toBeDeleted));

db.executeBulk(bulkDocs);
Henrik Barratt Due
  • 5,614
  • 1
  • 21
  • 22
  • Thanks Henrik! Either way, it looks like we have to include the documents as well even for deleting. I was hoping maybe if we supply only the id and rev, it should also work. – Vebito Mar 11 '15 at 12:46
  • The resulting json document will only contain the id, rev and _deleted fields – Henrik Barratt Due Mar 12 '15 at 13:43
  • Oh...you mean the bulkDocs or the resultant document after deletion.. because Im trying to delete in huge numbers and querying with http client so if I do include docs, it just hurts the performance real bad... so was looking for a way to minimise the response and request payloads.... thanks for the info anyway! – Vebito Mar 12 '15 at 17:52
0

If you only need a way to delete/update docs in bulk and you don't need to necessarily implement it in your own software, you can use the great couchapp at:

https://github.com/harthur/costco

You need to upload it to your own server with a couchapp deployment tool, and use a function like

function(doc) {
    if(doc.istodelete)  // replace this or remove to delete all docs
        return null;
}     

Read instructions and examples

giowild
  • 479
  • 5
  • 17