我们如何使用 CouchDB 的 _bulk_docs 和 all_or_nothing 选项?

How do we use CouchDB's _bulk_docs with all_or_nothing option?

CouchDB documentation 中,他们说我们可以批量插入文档,如果需要,可以使用 all_or_nothingnew_edits 选项。但看起来,all_or_nothing 键在我们这样使用时没有任何效果:

HOST="http://test:test@localhost:5984/mydb"

curl -vX POST "$HOST/_bulk_docs" \
    -H "Content-type: application/json" \
    -d @test.json

与 test.json:

{
    "all_or_nothing":true,
    "docs":[
        {"_id":"hello"},
        {"_id":"world"}
    ]
}

这会插入具有 helloworld ID 的文档。通过将 hello 替换为 hello1 来重新 运行 脚本应该会导致 hello1 被插入到数据库中,但是 world 文档的记录失败(因为它没有没有正确的 _rev),因此它们都应该失败,因为我们说 all_or_nothing。但最终,数据库中有 3 个文档:hellohello1world

我们如何将 all_or_nothing 与 CouchDB 一起使用?

我的用法是正确的。但是,我的尝试失败的原因不止一个:

  1. PouchDB 服务器简单地忽略(即使没有正确的错误)all_or_nothing 因为他们 do believe 这是正确的方法。

  2. Cloudant 简单地 因为他们保持他们的数据库服务是分布式的,事务事物不会让数据库扩展。

  3. CouchDB dropped all_or_nothing support in 2.0 version