我正在从Mongo数据库中检索文档,并将它们复制到内部存储。我发现检索和存储这些文档需要超过几秒钟的时间。我能做些什么来提高成绩吗?一些集合有1000多个文档。这是我所拥有的(用vb.net写的)
' 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发布于 2017-10-03 19:13:14
增加指数并没有多大帮助。减慢速度的是每次访问文档中的元素(GetRHS在已发布的代码中)。因此,作为修正,我将文档转换为字符串,然后解析关键字值对的字符串。希望我所发现的能帮助那些有同样问题的人
发布于 2017-09-23 14:18:27
如果没有添加索引,可以将索引添加到集合中。请参阅:https://docs.mongodb.com/manual/indexes/
另外,我建议使用执行状态来运行特定的Mongodb查询。示例:db.mycollection.find().explain("executionStats");,它将为您提供有关查询性能的更多统计信息。https://docs.mongodb.com/manual/reference/explain-results/#executionstats
https://stackoverflow.com/questions/46380372
复制相似问题