2017-09-23 53 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)。所以,作为一个修复,我将文档转换为一个字符串,然后解析字符串中的关键字 - 值对。希望我找到的东西可以帮助有同样问题的人