2015-04-12 17 views
0

我試圖在CentOS上連接到虛擬機中的mongodb(配置了selinux和防火牆)。我創建了一個名爲test的數據庫,其中包含一個名爲test的集合和一個視圖文檔。 我使用C#和最新的相關驅動程序2.0.0來連接數據庫。 代碼looke這樣的:在mongodb中查找()。tolistasync()timeout(System.TimeoutException :)

using System; 
using System.Dynamic; 
using System.Collections.Generic; 
using MongoDB.Driver; 
using MongoDB.Bson; 

namespace mongotest 
{ 
    class MainClass 
    { 
     public static void Main (string[] args) 
     { 
      MongoClientSettings settings = new MongoClientSettings(); 
      settings.Server = new MongoServerAddress ("mongotest", 21017); 
      MongoClient client = new MongoClient (settings); 

      System.Threading.Tasks.Task<List<BsonDocument>> datasetsTask = client.GetDatabase ("test").GetCollection<BsonDocument> ("test").Find (x => true).ToListAsync(); 

      foreach (BsonDocument dataset in datasetsTask.Result) { 
       try { 
        Console.WriteLine(dataset["_id"]); 
        try{ 
         Console.WriteLine("\t" + dataset["test"]); 
        } catch(Exception e) {} 
        try{ 
         Console.WriteLine("\t" + dataset["name"]); 
        } catch(Exception e) {} 
       } catch(Exception e) {Console.WriteLine ("Error: no property called _id");} 
      } 
     } 
    } 
} 

我檢查了數據庫robomongo。測試數據庫和測試集合在那裏。在我嘗試獲得結果的行中(在foreach循環的頭部),執行暫停30秒,然後拋出一個System.TimeoutException(我不得不將它張貼到pastebin中,因爲它太長了):http://pastebin.com/pp0kfgaH

倒行58是我認爲的真正的錯誤。但我不知道這是怎麼來到這個服務器地址。

回答