Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 923
ceremcem Avatar asked Oct 20 '16 00:10

ceremcem


People also ask

How does CouchDB store data?

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.

What query language does CouchDB use?

CouchDB uses HTTP protocol for API. It uses javascript as its query language to transform the documents and JSON to store data.


1 Answers

My usage was correct. However, there are more than one reason why my attempts are failed:

  1. PouchDB-server simply ignores (even without a proper error) all_or_nothing as they do believe this is the correct way.

  2. Cloudant simply drops this feature as they keep their database service distributed and transaction thing does not let the database scale.

  3. CouchDB dropped all_or_nothing support in 2.0 version.

like image 160
ceremcem Avatar answered Nov 15 '22 08:11

ceremcem