In the CouchDB documentation they say we can insert documents in bulk, with all_or_nothing
or new_edits
option if we want to. But it seems, all_or_nothing
key does not have any effects when we use like so:
HOST="http://test:test@localhost:5984/mydb"
curl -vX POST "$HOST/_bulk_docs" \
-H "Content-type: application/json" \
-d @test.json
with a test.json:
{
"all_or_nothing":true,
"docs":[
{"_id":"hello"},
{"_id":"world"}
]
}
This inserts documents which have hello
and world
ids. Re-running the script by replacing hello
with hello1
should cause hello1
to be inserted in the database but fail the world
document's recording (since it doesn't have correct _rev
), thus they both SHOULD fail because we said all_or_nothing
. But in the end, there are 3 documents in the database: hello
, hello1
and world
.
How do we use all_or_nothing
with CouchDB?
CouchDB stores data as "documents", as one or more field/value pairs expressed as JSON. Field values can be simple things like strings, numbers, or dates; but ordered lists and associative arrays can also be used. Every document in a CouchDB database has a unique id and there is no required document schema.
CouchDB uses HTTP protocol for API. It uses javascript as its query language to transform the documents and JSON to store data.
My usage was correct. However, there are more than one reason why my attempts are failed:
PouchDB-server simply ignores (even without a proper error) all_or_nothing
as they do believe this is the correct way.
Cloudant simply drops this feature as they keep their database service distributed and transaction thing does not let the database scale.
CouchDB dropped all_or_nothing
support in 2.0 version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With