{
"_id": ObjectId("5882ffbe553f7c3f043fbfdf"),
"AuditLog": null,
"Name": "Test",
"UserId": ObjectId("5839a1b8be46463ebc640cdc"),
"Address": {
"AddresType": null,
"Address1": "S.S",
"Address2": "Hy",
"City": "Hyd",
"Pincode": "50072",
"IsActive": true,
"Latitude": 17.497556,
"Longitude": 78.386541
}
}
我想使用_id
更新地址对象答案 0 :(得分:0)
如果你有正确的设置,你可以尝试一下。下面的代码找到包含filter
的文档,并使用update
构建地址嵌入文档,并使用UpdateOne
和filter
执行update
以更新地址doc的地址类型。
var filter = Builders<User>.Filter.Eq("Id", new ObjectId("5882ffbe553f7c3f043fbfdf"));
var update = Builders<User>.Update.Set("Address.AddresType", "Home");
var result = collection.UpdateOne(filter, update);