MongoDB:使用C#驱动程序更新除_id之外的整个文档 [英] MongoDB : update entire document except _id using C# driver
问题描述
我必须更新_id以外的所有字段. 我想避免手动更新16个字段... 所有新字段都存储在BsonDocument中
I have to update all the fields except _id. I want to avoid to manually update the 16 fields... All the new fields are stored inside a BsonDocument
感谢创意
推荐答案
正如@Philipp暗示的那样,有一种方法可以做到这一点.您实际上可以使用save
函数( http ://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-Save%3CTDocument%3Emethod ),这将在数据库端为您效劳.
As @Philipp hinted there is a way way to do this. You can actually use the save
function ( http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-Save%3CTDocument%3Emethod ) which will do what he says for you in the database end.
因此,假设您有以下文件:
So imagine you have a document of:
{
_id: {},
d: 1
}
并且_id
已经存在,它将用该文档替换先前的文档.
And that _id
already exists, it will replace the previous document with this one.
整洁吗?
这篇关于MongoDB:使用C#驱动程序更新除_id之外的整个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!