Aruna
Aruna

Reputation: 103

Getting error while deleting a document in couchdb using node-couchdb-api

var couchdb = require("couchdb-api");
var server = couchdb.srv(localhost, 5984, false, false);
var db = server.db("test");
var doc = db.doc("d5e1d042d579fcb1b3d4df07bc001f74");
doc.del(function (err, response) {
console.log(response);
console.log(err);
});

after that i am facing the problem,

null
{ error: 'bad_request', reason: 'Invalid rev format' }

but the corresponding document having the proper revision like 1-135dc47e3492a980fa45b3af9eb22a97 and proper data.

Please provide me the solution.

Thanks in advance.

Upvotes: 1

Views: 1984

Answers (1)

Dominic Barnes
Dominic Barnes

Reputation: 28429

I'm the creator of this module. The issue here is that you are attempting to delete the document without a revision number. (there is a _rev number on your document, but couchdb-api does not have that information) Any other attempt to write would also trigger this error under these conditions.

You have a couple options as it stands now:

Get the current document before attempting to write/delete

doc.get(function (err, body) {
    doc.del(function (err, results) {
        // the delete will be successful
    });
});

Explicitly set your revision number before attempting the write/delete

doc.body._rev = "1-myrevisionnumber";
doc.del(...);

I'm going to add a better error message here, and I'm considering adding a special flag that will tell couchdb-api to "force" a delete even if it doesn't have the latest revision number. (ie. it will call get before del in order to avoid MVCC)

Upvotes: 5

Related Questions