mongoose-transactions icon indicating copy to clipboard operation
mongoose-transactions copied to clipboard

Very possible transaction.remove bug

Open zzxoto opened this issue 6 years ago • 1 comments

I am not sure if this is bug but consider that my database collection had just 2 elements

var m1 = await model.findOne({name: "A"}); var m2 = await model.findOne({name: "B"}); transaction.remove('myModel', m1._id); await transaction.rollback(); I am intentionally rolling back, to imitate that there was an error in the very first remove attempt.

What would happen is, my database would now end up with 3 elements now with 3rd element being empty. Like: {name: "A", _id: ObjectId("...")}, {name: "B", _id: ObjectId("...")}, {_id: ObjectId("...")},
Looking at your run method, I think this error could be reproduced if the very first transaction was a failure. However , I was not able to make the very first remove transaction a failure, and therefore i ran transaction.rollback() instead.

I think this has to do with this.rollback set to 0 at very beginning. Again, am I missing something? Therefore I have prefixed the title with Very possible.

zzxoto avatar Jun 19 '18 01:06 zzxoto

Your example is not complete, can you please provide a working example?

daton89 avatar Feb 24 '20 11:02 daton89