apache / nano

Nano is now part of Apache CouchDB. Repo moved to https://GitHub.com/apache/couchdb-nano
https://github.com/apache/couchdb-nano
Other
1.13k stars 157 forks source link

[Bulk operations] Unable to set params such as all_or_nothing or new_edits #270

Closed ClintEsteMadera closed 9 years ago

ClintEsteMadera commented 9 years ago

As of version 6.1.2 of the library, the bulk function does not provide a way of specifying optional parameters supported by CouchDB's REST API, such as:

all_or_nothing (boolean) – Sets the database commit mode to use all-or-nothing semantics. Default is false. Optional new_edits (boolean) – If false, prevents the database from assigning them new revision IDs. Default is true. Optional

(params details were taken from CouchDB's official documentation )

Is there any chance for this to be included anytime soon in a future release?

Thanks very much in advance, Jonathan

jo commented 9 years ago

Yes, this should be possible. Will look at it tomorrow.

jo commented 9 years ago

@jchiocchio Can you please provide some code that reproduces this, or even better, a test? By looking at the code passing query options to db.bulk(docs, [params], [callback]) should still be possible.

pmanijak commented 9 years ago

Hey Jonathan / @jchiocchio try using bulk like this:

    var database = nano.use('alice');

    var bulkUpdate = {};
    bulkUpdate.docs = [];
    for (var index in docsToSave) {
        // These are CouchDB docs, with _id and _rev properties if you're doing an update
        bulkUpdate.docs.push(docsToSave[index]);
    }

    var options = {
        "all_or_nothing": true
    };

    database.bulk(bulkUpdate, options, function (err, response) {
        if (err) {
            return callback(err);
        }
        // Handle the response as per CouchDB spec
        for (var docIndex in response) {
            if (!response[docIndex].ok) {
                // Something went wrong ...
            }
        }
    }
jo commented 9 years ago

I close this for now. Please reopen with reproducable code, or a test.

chevcast commented 8 years ago

Took me way too long to figure out I had to supply an object with a docs property set to my array of documents. I just kept trying to pass the array directly and could not figure out why it was failing.