Search code examples
transactionscouchdbaciddocument-databasenosql

Single Node CouchDB, Multi Doc Transaction


Assuming there is a validate_doc_update function, in the design document, defined as:

{
   "_id": "_design/ddoc",
   "_rev": "12-133b5dad579f872884a9ccd6d4be5ee9",
   "language": "javascript",
   "validate_doc_update": "function(newDoc, oldDoc, userCtx) {
        if (oldDoc._rev != newDoc._rev) { throw('FAILED') }
   }"
}

If we perform a bulk update (_bulk_docs); is it transnational for more than one document?

Note: I've found this answer and have read the documents and have run some test code. And it seems it's a perfect way to perform transactions on CouchDB! But since I've not seen it on other places (and wondered why?); wanted to make sure that, this is not a mistake.


Solution

  • CouchDB dev here.

    This is not transactional, and it’s by design, even on a single node.

    The reason is that we don’t want to have any APIs in CouchDB that break when you go from a single node installation to a cluster installation.

    In a cluster, it is much harder to guarantee a multi-doc transaction, so CouchDB doesn’t even attempt it.