MongoDB Udate 查询在 C# 中使用类对象?
我将类对象存储在 mongodb 中,如下所示,
try
{
Sample risk = new Sample();
risk.Name = "ABC";
risk.Enable = true;
risk.Sender = "IBM";
risk.Target = "CITI";
MongoServer server = MongoServer.Create("mongodb://localhost");
MongoDatabase db = server.GetDatabase("DATABASE");
db.GetCollection<StockQuote>("SMAPLETABLE").Insert(risk);
}
catch (Exception e)
{
MessageBox.Show("Error");
}
现在我想更新相同的类实例,例如 db.GetCollection
我该怎么做一。
I am storing class object in mongodb like below,
try
{
Sample risk = new Sample();
risk.Name = "ABC";
risk.Enable = true;
risk.Sender = "IBM";
risk.Target = "CITI";
MongoServer server = MongoServer.Create("mongodb://localhost");
MongoDatabase db = server.GetDatabase("DATABASE");
db.GetCollection<StockQuote>("SMAPLETABLE").Insert(risk);
}
catch (Exception e)
{
MessageBox.Show("Error");
}
now i want to to update that same class instance like db.GetCollection<StockQuote>("SMAPLETABLE").Insert(risk);
how can i do this one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新文档有两种方法:
1.通过
Save
方法更新整个文档2.通过 原子更新:更新部分文档。例如,如果您需要使用
Name
“ABC
”更新文档的Enable
字段:一些注意事项:
There is two approaches two update document:
1.Via
Save
method and update etire document2.Via atomic update: update part of document. For example if you need update
Enable
field of document withName
"ABC
":Some notes: