将MongoDB聚集器响应转换为500K+记录需要大量时间
很抱歉提出重复的问题,但我提到了太多文章,但无法解决我的用例。
使用的技术
- nodejs
- mongodb(mongoclient)librabry用nodejs
我尝试了两种方法:
const records = client
.db(mongodbDATABASE)
.collection('subscriptions')
.aggregate(pipeline)
.toArray()
const Records =客户端 .db(mongodbdatabase) .Collection(“订阅”) .ggregate(管道) 而(等待records.hasnext()){ const uscription =等待records.next() //处理订阅 }
我在Compass和NoSQL-Booster中运行聚合管道查询,并且我的响应非常快(200ms),使用500K记录,但是每当我尝试通过使用上面的汇总结果将汇总结果转换为阵列格式方法(.toArray(),.hasnext())几乎需要 3-4分钟。
您能为此提供帮助,我如何将此聚合库转换为阵列格式,而不会影响性能?
Sorry to ask repeated questions, but I referred to too many articles but was not able to solve my use case.
Technology used
- NodeJs
- mongodb (MongoClient ) librabry with NodeJs
I have tried two approaches as below:
const records = client
.db(mongodbDATABASE)
.collection('subscriptions')
.aggregate(pipeline)
.toArray()
const records = client .db(mongodbDATABASE) .collection('subscriptions') .aggregate(pipeline) while (await records.hasNext()) { const subscription = await records.next() //TO DO with subscriptions }
I run aggregate pipeline query in compass and NoSQL-booster and I'm getting responses very quick (200ms) with 500K records but whenever I'm trying to convert the aggregate result to array format by using the above methods(.toArray(), .hasNext() ) it's almost taking 3-4 minutes.
Could you please help on it how I can convert this AggregationCursor to array format without much impacting the performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
光标模式不会一次获取所有数据,因此仅在200ms中返回。要获取500k行,无论您对客户端采用哪种方法,都需要一段时间,因为这将需要大量数据库服务器的工作。
the cursor pattern is not going to fetch all data at once, hence it is returning in only 200ms. to fetch 500k rows is going to take a while no matter what approach you take on the client, as this will require a lot of work for the database server.