You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In mongoose 5.7.3, seems there is no session option (or any option) on Model.remove API.
So how do I remove a document with condition in a transaction in mongoose?
Though I can do find a document first, then call Model.prototype.remove. But it would becomes 2 query to make, the problem is, document may be mutate between the 2 queries, which cause data inconsistency.
For example
0. Do something in transaction
Query the doc in transaction with { a: 1 }
(somebody else update the document outside of transaction to {a: 2} )
call doc.remove()
Do something in transaction
Commit transaction
If I'm correct, the transaction would succeed without error and the document will be deleted, which is unwanted.
If there we can use session in Model.remove, we can just call Model.remove(condition, {session}) and verify the nRemoved to get rid of the unwanted behavior.
The text was updated successfully, but these errors were encountered:
vkarpov15
added
enhancement
This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
and removed
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
labels
Oct 9, 2019
In mongoose 5.7.3, seems there is no
session
option (or any option) onModel.remove
API.So how do I remove a document with condition in a transaction in mongoose?
Though I can do find a document first, then call
Model.prototype.remove
. But it would becomes 2 query to make, the problem is, document may be mutate between the 2 queries, which cause data inconsistency.For example
0. Do something in transaction
doc
in transaction with{ a: 1 }
{a: 2}
)doc.remove()
If I'm correct, the transaction would succeed without error and the document will be deleted, which is unwanted.
If there we can use session in
Model.remove
, we can just callModel.remove(condition, {session})
and verify thenRemoved
to get rid of the unwanted behavior.The text was updated successfully, but these errors were encountered: