2011-04-11 52 views

回答

1

MongoDB的刀片是默認一種異步的,因爲它的發射後不管。錯誤檢查是明確的操作,或者您必須在驅動程序級別啓用安全模式。 如果您需要真正的異步操作:使用消息隊列。

0

在緩存世界中,'lazy-persistence'將被稱爲寫後置(write-behind)。看看這個:Cache/Wikipedia

可能最簡單的方法是使用C#異步方法調用。這將告訴您如何:

的代碼看起來是這樣的:

  • 定義自己的委託:

    private delegate void InsertDelegate(BsonDocument doc); 
    
  • 使用它

    MongoCollection<BsonDocument> books = database.GetCollection<BsonDocument>("books"); 
        BsonDocument book = new BsonDocument { 
         { "author", "Ernest Hemingway" }, 
         { "title", "For Whom the Bell Tolls" } 
        }; 
    
        var insert = new InsertDelegate(books.Insert); 
    
        // invoke the method asynchronously 
        IAsyncResult result = insert.BeginInvoke(book, null, null); 
    
        // DO YOUR OWN WORK HERE 
    
        // get the result of that asynchronous operation 
        insert.EndInvoke(result); 
    

希望 幫助。