Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transaction mongodb

I need to write into two different mongodb collections using an 'all or nothing' process. Fyi I use NodeJs in my backend side.

As far as I know MongoDb provides atomicity when it comes to a single collection, but it does not when we need to write into multiple collections.

So I'd like to know a way of emulating this a transaction in nodejs/mongodb in order to avoid writing into one collection if the other failed and also getting the possibility of doing a 'roll back' if the second process fails.

Thank you guys!

like image 314
Mochics Avatar asked Aug 27 '26 11:08

Mochics


1 Answers

Starting from version 4.0 MongoDB will add support for multi-document transactions. Transactions in MongoDB will be like transactions in relational databases. For details visit this link: https://www.mongodb.com/blog/post/multi-document-transactions-in-mongodb?jmp=community

like image 127
Pranab Sharma Avatar answered Aug 29 '26 03:08

Pranab Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!