我正在尝试连接到MongoDB数据库:
Dim server As MongoServer = MongoServer.Create("mongodb://localhost")
Dim db As MongoDatabase = server("mydb")
Dim coll As MongoCollection = db("coll")
Dim query = New QueryDocument("name","sid")
Dim item As BsonDocument = coll.FindOneAs(query)
最后一行抛出错误,并显示:
Public Overridable function FindOneAs(documentType As System.Type)As Object':MongoDB.driver.queryDocument类型的值无法转换为System.Type
现在我知道这里传递的对象很可能是Type
,但后来我无法继续。我应该传递什么而不是QueryDocument来执行我的查询?
答案 0 :(得分:1)
您应该使用Query
类的静态方法,例如EQ
,这意味着等于。 MongoDb的其他运营商也位于该类。您可以找到详细信息here。
Dim server As MongoServer = MongoServer.Create("mongodb://localhost")
Dim db As MongoDatabase = server("mydb")
Dim coll As MongoCollection = db("coll")
Dim query = Query.EQ("name","sid")
Dim item As BsonDocument = coll.FindOneAs(query)