Is there any way of using transactions in MongoDB 4.0 with mongoose, without using Promises
, I want to use Callbacks
only?
I read this post post but didn't find anything with Callbacks.
Please help me.
Is there any way of using transactions in MongoDB 4.0 with mongoose, without using Promises
, I want to use Callbacks
only?
I read this post post but didn't find anything with Callbacks.
Please help me.
I would assume that you can do something along the lines:
mongoose.startSession()
.then(session => {//do some db operation})
.then(//another one)
.then(mongoose.endSession())
.catch(session.abortTransaction());
Please also refer to this question. It's not specific for MongoDB 4.0, but might help.
Mongo DB not support Multi-Document Transactions:
When a single write operation (e.g. db.collection.updateMany()) modifies multiple documents, the modification of each document is atomic, but the operation as a whole is not atomic.
You can read more in the documentation:MongoDB Documentation
But there are some solutions for this, try to use this library: https://www.npmjs.com/package/mongoose-transactions