Search code examples
node.jsmongodbtransactionsrabbitmqamqp

ACID transaction in node.js


Using node.js I'd like to read a RabbitMQ queue and write the message to a MongoDB database. How do I wrap the read and the write within an ACID transaction so the whole thing either works or fails?


Solution

  • Mongo recommends emulate two-phase commit with the following pattern:

    https://docs.mongodb.com/manual/core/write-operations-atomicity/

    Also it is already implemented:

    https://github.com/rystsov/mongodb-transaction-example