2016-02-05 36 views
0

我無法獲得VB.net連接到MongoDB的replicaset - 它會拋出異常MongoDB的查詢在VB.Net

dim mongo as MongoDBClient 
dim mgDB as MongoDatabase 
dim mgcol as MongoCollection(of Bob) 

public class Bob 
    public property ID as ObjectID 
    public property Name as string 
end class 

sub Main() 
    try 
    mongo = New MongoClient("mongodb://ip:port,ip:port,ip:port/?replicaSet=Bob") 
    mgDB = mongo.GetDatabase("test") 
    mscol = mgDB.Collection(of Bob)("test.me") 

    mgDB.GetCollection("test.me").Find(MongoDB.Driver.Builders.Query.Exists("id")) 

catch ex as Exception 
console.writeline(ex) 
end try 
end sub 

我不知道我應該如何通過VB .NET來查詢?

回答

0

我得到這個工作

Dim _client As IMongoClient 
Dim _db As IMongoDatabase 

Sub Main() 
    System.Console.WriteLine("Hi, Bob!!") 

    Try 

     _client = New MongoClient("mongodb://mongoone:27020,mongotwo:27021,mongothree:27020/?replicaSet=Bob") 
     _db = _client.GetDatabase("Test") 

     Dim mgCol = _db.GetCollection(Of Bob)("test.me") 
     Dim mybob As Bob 
     mybob = New Bob 
     mybob.Name = "Sam6" 
     mybob.ID = ObjectId.GenerateNewId 

     'mgCol.InsertOne(mybob) 

     getSomedata().Wait() 
     'getDataByFilterExtists().Wait() 
     'getMetaCardSpectrum().Wait() 
     getMetaCardSpectrumObj().Wait() 

    Catch ex As Exception 
     Console.WriteLine(ex) 
    End Try 


End Sub