'Pymongo overwrites data when I use update_one Python [duplicate]
I'm trying to solve an issue in Pymongo. I have a dictionary like this :
{
"_id": 6,
"engineers": {
"1": {
"name": "George ",
"hours": "2"
}
}
}
And I want to insert another record inside the field engineers:
{
"_id": 6,
"engineers": {
"1": {
"name": "George ",
"hours": "2"
}
"2": {
"name": "Spyros",
"hours": "12"
}
}
}
I use the update command :
dic = "2": {
"name": "Spyros",
"hours": "12"
}
x = mydb.mycollection.update_one({ "_id": "6" },{ "$set": {"engineers":dic} })
However, this command overwrites the previous data!
Any help, please?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
