0
我需要在不同文档(MongoDB
)中插入(或创建)一个字段。
这是我的代码:如何在查询中使用objectId .net
var myDB = mclient.GetDatabase("MasterDB");
var collection = myDB.GetCollection<BsonDocument>("MasterCollection");
var list = await collection.Find(new BsonDocument())
.Limit(2)
.Skip(1)
.ToListAsync();
foreach (var docs in list)
{
var updoneresult1 = await collection.UpdateManyAsync(
Builders<BsonDocument>.Filter.Eq("_id", docs["_id"].ToString()),
Builders<BsonDocument>.Update.Push("OfficeCode",
Convert.ToInt32(txtOfficeCode.Text)));
}
什么是你的问题?你有错误吗? –
我没有错误,但它不起作用,我想知道如果我可以匹配docid的ObjectId与文档的ObjectId。我试图在2个不同的文档中添加“OfficeCode”字段 – fred