我想如果文档存在只更新一个属性,如果不存在,则不仅要在mongo中插入一个属性(包含所有属性),
例如:
var customer = new Customer
{
Name="David",
Family="Green",
CustomerId="12",
Gender="male"
};
var filter = Builders<Customer>.Filter.Where(s => s.CustomerId == customer.CustomerId);
var updateDefination =
(Builders<Customer>.Update.Set(s => s.Name, customer.Name));
var options=new UpdateOptions
{
IsUpsert = true,
};
MongoHelper.GetCollection<Customer>().UpdateOne(filter, updateDefination,options);
如果具有该ID的客户不存在,如何插入具有所有属性的客户对象。