How to delete couchdb document with empty document id?

I see the document in db as follows: {_id: ", _rev:" 1-2f11e026763c10730d8b19ba5dce7565 ", prohibited:" must update the existing package "_ last _rev"}

Everything that I see in the documents refers to a document with an identifier, but, of course, this cannot be.

I'm not quite sure how this happened, most likely something happened between the chair and the keyboard, but I wanted to know if there was an opportunity to fix this without starting.

+4
source share
1 answer

There is a bug in CouchDB that allows this to happen. I believe that it was introduced in v1.1.0 and will be fixed in versions v1.1.1 and v1.2.0.

The error is that _update functions can create documents with identifiers with an empty string. To delete a document, use the same update function and use the same error.

For instance:

 { "_id": "_design/example", "updates": { "del_blank": "function(doc, req) { var doc = {_id:'', _rev:req.query.rev, _deleted:true}; return [doc, 'Trying to delete nastydoc@ '+doc._rev]; }" } } 

Just indicate the version that gives you the problem and it marks it deleted.

 $ rev="1-2f11e026763c10730d8b19ba5dce7565" $ curl -XPOST localhost:5984/db/_design/example/_update/del_blank?rev=$rev Trying to delete nastydoc@1-2f11e026763c10730d8b19ba5dce7565 $ curl localhost:5984/db/_all_docs {"total_rows":1,"offset":0,"rows":[ {"id":"_design/example","key":"_design/test","value":{"rev":"2-b9bfbedff0c09fab88ff36d06cec0d34"}}, ]} 
+7
source

Source: https://habr.com/ru/post/1307119/


All Articles