【发布时间】:2017-12-28 18:55:50
【问题描述】:
我想在 web api 中实现 Patch 动作, 考虑我在 mongo 中有这样的客户集合:
public string Id{ get; set; }
public string Name{ get; set; }
public string Family{ get; set; }
public string Sex{ get; set; }
public string City{ get; set; }
public string CustomerId{ get; set; }
在我的 api 中,我收到这个对象作为输入。客户端可以编辑这些字段中的一个或多个,如果属性为空,则表示该值应保持以前的值。 我想做的是在 mongo 查询中我想说如果属性为 null 不要更新考虑这个:
var filter = Builders<Customer>.Filter.Eq(s => s.CustomerId, CustomerId);
var builder = Builders<Customer>.Update.Set(???)//set only not null values
mongo.UpdateOne(filter, builder);
*顺便说一下,任何更好的解决方案都值得赞赏
【问题讨论】:
标签: c# mongodb asp.net-web-api http-patch