I have been attempting to modify the nested value data1
within a MongoDB document:
{
"content": {
"data": {
"data1": "Some data",
"data2": "Better data"
},
"location": {
"coordinates": [
45,
45
],
"type": "Point"
}
},
"_id": "647e40c590bc322763bdf182",
"title": "test",
"description": "Here is some updated description",
"tags": [
"test",
"pic",
"newTag"
],
"dataType": "NOTREFERENCED",
"createdAt": "2023-06-05T20:08:37.345Z",
"updatedAt": "2023-06-07T18:37:23.134Z",
"__v": 0
}
Nevertheless, I am unable to achieve this. I am utilizing mongoose
and have experimented with the subsequent approaches:
const id = "647e40c590bc322763bdf182"
await this.model.findByIdAndUpdate(id,{ $set: {content.data.data1: "Updated value"}},{new: true,});
await this.model.findByIdAndUpdate(id,{ content.data.data1: "Updated value"},{new: true,});