How to purge CouchDB documents

邮差的信 提交于 2021-01-27 11:31:24

问题


I need to fully delete, as in Purge, several documents from CouchDB version 2.1.

I have been reading about /db/_purge on docs.couchdb.org, but the process is not clear to me. There is a sentence "The format of the request must include the document ID and one or more revisions that must be purged".

How do I do this in Postman or in a browser? Do I actually enclose my doc _id & rev(s) in braces? I am struggling with how to correctly format a _purge request.


回答1:


Note that document purging is only supported in CouchDB versions prior to 2.0, and from 2.3 onward. Early versions of clustered CouchDB (2.0.x and 2.1.x) did not support purging, although this was poorly documented!

The documentation explains, and provides an example:

{
    "c6114c65e295552ab1019e2b046b10e": [
        "3-b06fcd1c1c9e0ec7c480ee8aa467bf3b",
        "3-0e871ef78849b0c206091f1a7af6ec41"
    ]
}

So that means in the format of:

{
    "<doc id>": [
        "<rev>",
        "<rev>"
    ]
}

This should be the body of your HTTP request, with a Content-Type of application/json. You won't be able to do that in a browser, without using JavaScript.

With curl it would look like:

curl -X POST http://<server url>/<database>/_purge -H 'Content-Type: application/json' -d '{"<doc id>":["<rev1>","<rev2>"]}'



回答2:


As of now, it is my understanding that _purge does not work in 2.0 and 2.1.

For more information look at this JIRA post.




回答3:


I just wrote this tool to purge and compact databases in CouchDB. https://github.com/nisbus/couch_db_cleaner
I hope the documentation in the README is clear and it helps.



来源:https://stackoverflow.com/questions/45741204/how-to-purge-couchdb-documents

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!