mongodb更新文档vb.net



一直遵循C#教程,只是将语法转换为VB。当我关注更新文档的C#教程时,我无法转换语法。

具体来说,这些

var filter = Builders<BsonDocument>.Filter.Eq("name", "Juni");
var update = Builders<BsonDocument>.Update
    .Set("cuisine", "American (New)")
    .CurrentDate("lastModified");

尝试使用filter.eq()与教程相同的方式时,我弄错了参数错误。

这是我到目前为止所做的代码。我故意遗漏了连接字符串。

        Dim collection As IMongoCollection(Of RepReport) = db.GetCollection(Of RepReport)("BDS_Rep_Reports")
        Dim query As IQueryable = From rpt In collection.AsQueryable() Where rpt.IsInSql = False Select rpt
        For Each rpt As RepReport In query
            'Update document and change the InSql column here.
        Next

因此,我基本上只想更新查询中的每个文档,一个不同时更新。

我没有看到原始C#和您的VB代码之间的任何对应关系。VB等效只是:

'at the top of the file:
Option Infer On
'later within your method:
Dim filter = Builders(Of BsonDocument).Filter.Eq("name", "Juni")
Dim update = Builders(Of BsonDocument).Update.Set("cuisine", "American (New)").CurrentDate("lastModified")

最新更新