如果我有一个看起来像这样的文档:
{
"_id" : 1,
"name": "Homer J. Simpson",
"income" : 45000,
"address": {
"street": "742 Evergreen Terrace",
"city": "Springfield",
"state": "???",
"email": "homer@springfield.com",
"zipcode": "12345",
"country": "USA"
}
}
并希望对地址文档中的某些字段进行更新(保持其他字段不变),如果它们尚不存在,则插入新字段,例如:
{
"address": {
"email": "homer@gmail.com",
"zipcode": "77788",
"latitude" : 23.43545,
"longitude" : 123.45553
}
}
有没有办法一次进行一次原子更新,或者您是否需要遍历新数据中的键/值并.update()
为每个值执行一次?