Using spread operator on a SubDocument does not give the original object that mongoose is wrapping #14912
Open
2 tasks done
Labels
developer-experience
This issue improves error messages, debugging, or reporting
Milestone
Prerequisites
Mongoose version
8.6.3
Node.js version
20.14.0
MongoDB server version
6.8.0
Typescript version (if applicable)
5.6.2
Description
When using the spread operator on a SingleNested Document (a SubDocument) I get:
But the actual properties of the object Mongoose is wrapping aren't there (unless I look inside _doc)
However, if I do the spread operator on a nested document (Document) I get the original properties of the document.
And by original properties I mean for example this, and none of the Mongoose properties:
Steps to Reproduce
Create two schemas
Create Document instances of these two, such as userWithSubDoc and userWithNestedDoc with the properties set. Then run
Then using a debug tool examine the constants to see what the live objects look like.
You should see that the output of the spread operation is quite different and as described in this issue description.
Expected Behavior
I would expect the spread operator to work the same way on a Document instance and a SingleNested instance☺️ And at least give me the properties of the object that Mongoose is wrapping.
The text was updated successfully, but these errors were encountered: