2013-02-20 61 views
1

我需要獲取更新查詢狀態意味着,查詢是否成功執行。我如何做到這一點。如何獲得Mongo更新查詢狀態在c#

MongoCollection<BsonDocument> Updatecollection = 
          MongoDBs.GetCollection<BsonDocument>(collectionName); 
Updatecollection.Update(query, update, UpdateFlags.Multi); 

這是我用來更新我的集合的方式,請幫助我獲取查詢狀態。

由於事先 希瓦

回答

0

Update方法返回WriteConcernResult對象包含該更新的結果。

有關該對象的詳細信息,請參閱docs

例如:

var result = Updatecollection.Update(query, update, UpdateFlags.Multi); 
Console.WriteLine("{0} docs updated", result.DocumentsAffected); 
+0

嗨@JohnnyHK感謝您的答覆,我用UpdatedExisting與我的查詢,並得到了布爾值,也試圖與documentsAffected,它給受影響的文件的數量。請你告訴我如何得到查詢異常。 – siva 2013-02-20 15:18:20