This is my collection in mongoAltas:
{
"_id":{"$oid":"5ff35fefa0652d23c637bf51"},
"plantId":"3",
"status":"SUCCESS",
"healthMonitor":[{"PlantName":""}]
}
When I am trying to insert any data to the nested array "PlantName", the document is not updated and returns null. I tried $push
and $set
and tried find_one_and_update
and just update_one
but both does not work
Here is the update I tried:
collection.find_one_and_update({'plantId':3},
{ '$push': {
"healthMonitor.$.PlantName": "Herb"
}
})
collection.find_one_and_update({'plantId':3},
{ '$push': {
"healthMonitor":[{PlantName": "Herb"}]
}
})
If any one know how the code works for nested document please help me.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…