更新mongodb文档中的特定字段 [英] Update specific field in mongodb document
本文介绍了更新mongodb文档中的特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用C#驱动程序在小型项目中使用MongoDb,现在我坚持更新文档. 试图弄清楚如何更新字段 AVG (int)
I using C# driver to use MongoDb in small projects, and now I stuck with updating documents. trying to figure out how to update the field AVG (int)
这是我的代码:
IMongoCollection<Student> studentCollection = db.GetCollection<Student>("studentV1");
Student updatedStudent = new Student() { AVG = 100, FirstName = "Shmulik" });
studentCollection.UpdateOne(
o=>o.FirstName == student.FirstName,
**<What should I write here?>**);
有一种简单干净的方法来更新特定字段,例如方法ReplaceOne(updatedStudent)
?
there is simple and clean way to update specific field(s) like the method ReplaceOne(updatedStudent)
?
推荐答案
尝试一下..& 了解更多信息
Try this..& for more info
IMongoCollection<Student> studentCollection = db.GetCollection<Student>("studentV1");
Student updatedStudent = new Student() { AVG = 100, FirstName = "Shmulik" });
var update = Update<Student>.
Set(s => s.AVG, "500").
Set(s => s.FirstName, "New Name");
这篇关于更新mongodb文档中的特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文