-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transaction retries corrupt subdocument arrays #14340
Comments
I did some digging and found that the |
Any chance to add this to v7? : ] |
…n array when transaction fails Fix #14340
@juona yep we will backport |
Avoid corrupting $set-ed arrays when transaction error occurs
Hey @vkarpov15 — we are seeing some strange behavior that I think is related to this issue. Only in Jest, and on Mongoose v6.12.3, our subdocument arrays are being transformed into objects like the OP posted. We're seeing this when using the Does this ring any bells for you? |
Prerequisites
Mongoose version
8.1.1
Node.js version
18.18.2
MongoDB server version
5
Typescript version (if applicable)
No response
Description
Hello, me again!
Result: the whole array is saved incorrectly and can even become corrupted, in turn ruining the whole document.
I noticed that in more recent versions document arrays are actually proxy objects, and my guess is that this might be causing problems, especially when using
.pull()
/.splice()
.Steps to Reproduce
Expected Behavior
If
.push()
is usedThe total number of documents added to the array grows exponentially with every retry - it is 2^n, where n is the number of retries (forgive me, can't go without a lol here :)).
Expectation: only one document is added.
If
.pull()
or.splice()
is usedThe document that is saved in the database looks like this:
As you can see, the array got converted into an object, and that's why I'm throwing suspicious looks at the Proxy object used for document array.
The text was updated successfully, but these errors were encountered: