2017-09-23 50 views
0

我從Mongo數據庫檢索文檔並將其複製到內部存儲。我發現檢索並存儲上百個這些文檔需要幾秒鐘的時間。有什麼我可以做的改善表現?一些集合有超過1000個文檔。這裏是我有(用vb.net寫的)如何提高Mongo文檔檢索性能

' get the documents from collection "reqitems" and put them in "collection" 
Dim collection As IFindFluent(Of BsonDocument, BsonDocument) = _ 
          reqitems.Find(Builders(Of BsonDocument).Filter.Empty) 
ReDim model.ReqItems(TotalCollection.ToList.Count) ' storage for the processed documents 
For Each item As BsonDocument In TotalCollection.ToList() 
    ' note: given a string a=x, "GetRHS" returns x 
    Dim parentuid As String = GetRHS(item.GetElement("parentuid").ToString) 
    Dim nodename As String = GetRHS(item.GetElement("nodename").ToString) 
    ' .... about a dozen of these elements 
    ' .... process the elements and copy them to locations in model.ReqItems 
next 

回答

0

添加索引並沒有真正的幫助。減慢它的速度是逐個訪問文檔中的元素(發佈代碼中的GetRHS)。所以,作爲一個修復,我將文檔轉換爲一個字符串,然後解析字符串中的關鍵字 - 值對。希望我找到的東西可以幫助有同樣問題的人