Reputation: 4270
I was wondering why:
const props = {
excluded: true
}
const image = await Image.findByIdAndUpdate(
imageId, {
$set: 'image.ingest': props
}, {
new: true
}
)
Doesn't update the image document with the excluded
field whereas:
const props = {
excluded: true
}
const image = await Image.findById(imageId);
image.ingest = {
...image.ingest,
...props
};
await image.save();
does?
Upvotes: 0
Views: 280
Reputation: 15187
Your problem is you forgot to use { }
after $set
. Check this example.
Also, checked using mongoose
this query and works fine:
var updated = await model.findByIdAndUpdate(id,
{
"$set":{
"image.ingest":"new value"
}
},{
"new":true
})
Upvotes: 1