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
And than trying to do an update of a single child like results in error
updateData = { name: {en: "en Name", it: "it Name"} }
Parent.findOneAndUpdate({ 'children._id': id }, { 'children.$.name': updateData.name }, { new: true })
OR
Parent.findOneAndUpdate({ 'children._id': id }, { $set { 'children.$.name': updateData.name } }, { new: true })
gives the following error:
Cast to string failed for value \"{ it: 'it Name', en: 'en Name' }\" (type Object) at path \"name.$*\"
Of course in my case parent an child have more attributes, and i want to update only the attributes that are passed that are present in the update data however if i just try to set the whole 'children.$' as updateData i lose already present data because i'm overwriting the whole sub Document
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Update the sub Document wihout overwriting it as a whole
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node: 14.16.0
mongoose: 5.12.10
mongodb: 4.4.6
The text was updated successfully, but these errors were encountered:
foldess
changed the title
Setting map on update with and Object throws an Error
Setting map on update with an Object throws an Error
Jul 23, 2021
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Creating an schema like:
And than trying to do an update of a single child like results in error
gives the following error:
Of course in my case parent an child have more attributes, and i want to update only the attributes that are passed that are present in the update data however if i just try to set the whole 'children.$' as updateData i lose already present data because i'm overwriting the whole sub Document
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Update the sub Document wihout overwriting it as a whole
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node: 14.16.0
mongoose: 5.12.10
mongodb: 4.4.6
The text was updated successfully, but these errors were encountered: