Mongoose's session.withTransaction helper is only executing the first write. Here's the code:
const session = await mongoose.startSession();
await session.withTransaction(async () => {
const member = await Member.create([{
name: 'John Doe'
email: 'johndoe@example.com',
}], { session });
await User.updateOne({ _id: req.user.id }, { member: member._id }, { session });
});
This code creates a new Member in the database, but does not update the User. Isn't the point of a transaction that it only goes through if every operation succeeds? What am I doing wrong; or is this just not possible with Mongoose?
Mongoose: 5.9.26, Node.js: 14.9.0