错误:表达式不会使用vb.net在mongodb中生成值

时间:2013-12-24 06:48:12

标签: vb.net mongodb

    Imports MongoDB.Bson
    Imports MongoDB.Driver
    Imports MongoDB.Bson.IO

代码:

    Dim sQuery = Query.EQ("name", "abc")
    Dim sUpdate = Update.Set("title", "rocks")
    Dim sResult As SafeModeResult = tblBooksCustom.Update(sQuery , sUpdate )

它不会编译,它在Update.Set失败并给出了 以下消息:

  

表达式不会产生值。

任何人都可以帮我解决这个错误。

干杯。

2 个答案:

答案 0 :(得分:1)

我测试了这段代码,但没有错误

MongoClient mc = new MongoClient("mongodb://localhost:27017");

        MongoServer server = mc.GetServer();
        server.Connect();
        MongoDatabase db = server.GetDatabase("testdb");

        MongoCollection<BsonDocument> col = db.GetCollection("mycollection");
        BsonDocument mycollection = new BsonDocument {
            { "name", "abc"},
            { "title", "b"}};
        col.Insert(mycollection);

        var sQuery = Query.EQ("name", "abc");
        var sUpdate = MongoDB.Driver.Builders.Update.Set("title", "rocks");
        SafeModeResult sResult = col.Update(sQuery, sUpdate);

你可以测试其他新系列吗?

答案 1 :(得分:0)

最后我解决了这个问题,这是vb.net代码,希望这有助于有人寻找它:

 Dim server As MongoServer = MongoServer.Create("mongodb://localhost")
 Dim db As MongoDatabase = server("tutorial1")
 Dim books As MongoCollection(Of BsonDocument) = db.GetCollection(Of BsonDocument) ("bookdetails")

 Dim query = New QueryDocument() From {{"author", "Ernest Hemingway"}, {"title", "For Whom the Bell Tolls"}}
 Dim update = New UpdateDocument() From {{"$set", New BsonDocument("title", "Cat's Cradle")}}
 Dim updatedBook = books.Update(query, update)