MongoDB连接到VB.NET Visual Studio 2013

时间:2014-03-14 15:26:38

标签: vb.net mongodb

我想将MONGO DB连接到我正在制作的VB应用程序。我安装了必要的驱动程序,我的MongoDB服务器运行完美。我可以使用MongoVUE访问它,但通过VB以某种方式连接不起作用

    Imports MongoDB.Driver
    Imports MongoDB.Driver.Linq
    Imports MongoDB.Driver.Builders
    Imports MongoDB.Bson

    Public Class frmMongoDB
    '<ObsoleteAttribute("Use MongoClient, GetServer and GetDatabase instead.")>

    Private Sub frmMongoDB_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim server As MongoServer
    Dim db As MongoDatabase
    Dim coll As MongoCollection

    server = MongoServer.Create("mongodb://localhost:27017")
    db = server("db1")
    coll = db("table1")

称为服务器的行加下划线并说&#34;公共共享功能创建为(connectionString为MongoDB.Driver.Mongo服务器已废弃,请改用MongoClient.GetServer&#34;

我已经尝试过Dim服务器作为MongoServer = MongoServer.Create(&#34; mongodb:// localhost&#34;)

但也不会工作。请帮忙。

1 个答案:

答案 0 :(得分:3)

它反映了C# instructions

Imports MongoDB.Driver

Sub Main()
    Dim client As MongoClient
    Dim server As MongoServer
    Dim db As MongoDatabase
    Dim col1 As MongoCollection

    client = New MongoClient("mongodb://localhost")
    server = client.GetServer()
    db = server.GetDatabase("db1")
    col1 = db.GetCollection("collection_one")

End Sub