您如何删除带有空“"符号的CouchDB文档?文件编号? [英] How do you delete a couchdb document with an empty "" document id?
问题描述
我看到数据库中的文档是这样的: {_id:",_ rev:"1-2f11e026763c10730d8b19ba5dce7565",禁止:必须提供最新的_rev才能更新现有软件包"}
I see the document in the db as this: {_id: "", _rev: "1-2f11e026763c10730d8b19ba5dce7565", forbidden: "must supply latest _rev to update existing package"}
我在文档中看到的所有内容都显示了带有ID的文档,但这当然不会发生.
Everything I see in the docs shows referring to the document with the ID, but of course this can't happen.
我不确定这是怎么发生的,很可能是椅子和键盘之间有问题,但是我想知道是否有可能在不重新开始的情况下进行修复.
I'm not exactly sure how this happened, most likely something faulty between the chair and keyboard, but I wanted to know if there was a possibility of fixing this without starting over.
推荐答案
CouchDB中有一个错误可以使这种情况发生.我相信它是在v1.1.0中引入的,并将在v1.1.1和v1.2.0中得到修复.
There is a bug in CouchDB that allows this to happen. I believe it was introduced in v1.1.0 and will be fixed in v1.1.1 and v1.2.0.
错误在于_update
函数可以创建带有空字符串ID的文档.要删除文档,请使用相同的更新功能并利用相同的错误.
The bug is that _update
functions can create documents with empty-string IDs. To delete the document, use the same update function and exploit the same bug.
例如:
{ "_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];
}"
}
}
仅提供给您带来问题的修订版,并将其标记为已删除.
Simply provide the revision that is giving you problems and it will mark 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"}},
]}
这篇关于您如何删除带有空“"符号的CouchDB文档?文件编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!