Error when trying to update primitives at the bottom of multidimensional arrays #13372
Closed
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
7.1.0
Node.js version
17.9.1
MongoDB server version
4.4.21
Typescript version (if applicable)
5.0.4
Description
When attempting to modify a multidimensional array of primitives (e.g.
[[Number]]
), changing the values and attempting a save causes an error:Steps to Reproduce
I believe the problem is something to do with how the update command is generated, it seems to loose all sense of what the array is. Looking at the
getChanges()
(which I have documented in the code sample) It seems like it's not even sure where in the array it's trying to set the values and it's also trying to put an entire empty shell of the original object shape into a single slot in the array.One other note: I was having the same problem in version 5 of mongoose. I upgraded versions hoping that would fix it. I don't have as thorough documentation of what was going wrong in version 5, so I can't be confident that nothing has changed about the bug, but based on this I feel confident saying this wasn't caused by a recent change.
Expected Behavior
I expect the document to be updated properly and not error out.
potential fix
I am not an expert on this repo, but my own experimenting showed that changing the arrayPath on the integer array helped substantially. The following code works properly:
For some reason, the array path is being set to
intArray.$
. On a normal single array the arrayPath defaults tointArray
. On the 2d object array, the arrayPath defaults toobjArray.0
. But for some reason on a 2d integer array, it'sintArray.$
. I think that it may be set that way for use by other commands likepopulated()
, but_markModified()
is just presuming that the path for querying whether there are any items in the list will be the same as the command to set a single item in the list?The text was updated successfully, but these errors were encountered: