MongoDB Aggregation V/S简单查询性能? [英] MongoDB Aggregation V/S simple query performance?

查看:69
本文介绍了MongoDB Aggregation V/S简单查询性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在问这个问题,因为我认为这个问题应该在与此 mongodb-aggregation-match-vs-查找速度.现在,我想到了为什么要增加服务器上的计算时间,因为好像我将进行更多的计算,那么我的服务器负载将变得更多,所以我尝试使用聚合,并且我认为我现在朝着正确的方向发展.但是稍后在我之前的问题 andreas-limoli 告诉我,不要使用聚合,因为它很慢,而且使用简单查询和服务器上的计算.现在,从字面上看,我对应该使用的内容感到厌烦,从一年开始,我就与mongoDB一起工作,但是当数据大小增加时,我对其性能没有任何了解,因此我完全不知道应该选择哪个.

如果聚合的速度比是否由于$ lookup慢,我在任何地方都找不到,还有一件事情,因为$ lookup是我考虑使用聚合的首要考虑因素,否则我必须串行执行许多查询然后在服务器上进行计算,这在聚合之前对我来说似乎很差.

在将数据从一个管道传递到另一个管道时,我还阅读了有关mongodb聚合的大约100MB的限制,因此人们如何有效地处理这种情况以及是否打开磁盘使用情况,这是因为磁盘使用情况比人们处理该情况要慢得多.

我还提取了30,000个样本集合,并尝试使用$ match和find查询运行聚合,我发现聚合比find查询快一点,后者执行聚合需要180毫秒,而执行find需要220毫秒.

请帮帮我,这对我真的很有帮助.

解决方案

MongoDB中的聚合框架类似于SQL中的联接操作.聚合管道通常是资源密集型操作.因此,如果您的工作对简单查询感到满意,则应首先使用该查询.

但是,如果绝对必要,则可以使用聚合管道,以防需要从多个集合中获取数据.

I am reasking this question as i thought this question should be on seperate thread from this one in-mongodb-know-index-of-array-element-matched-with-in-operator.

I am using mongoDB and actually i was writing all of my queries using simple queries which are find, update etc. (No Aggregations). Now i read on many SO posts see this one for example mongodb-aggregation-match-vs-find-speed. Now i thought about why increasing computation time on server because as if i will compute more then my server load will become more, so i tried to use aggregations and i thought i am going in right direction now. But later on my previous question andreas-limoli told me about not using aggregations as it is slow and for using simple queries and computing on server. Now literally i am in a delimma about what should i use, i am working with mongoDB from a year now but i don't have any knowledge about its performance when data size increases so i completely don't know which one should i pick.

Also one more thing i didn't find on anywhere, if aggregation is slower than is it because of $lookup or not, because $lookup is the foremost thing i thought about using aggregation because otherwise i have to execute many queries serially and then compute on server which appears to me very poor in front of aggregation.

Also i read about 100MB restriction on mongodb aggregation when passing data from one pipeline to other, so how people handle that case efficiently and also if they turn on Disk usage then because Disk usage slow down everything than how people handle that case.

Also i fetched 30,000 sample collection and tried to run aggregation with $match and find query and i found that aggregation was little bit faster than find query which was aggregation took 180ms to execute where as find took 220 ms to execute.

Please help me out guys please it would be really helpful for me.

解决方案

Aggregation framework in MongoDB is similar to join operations in SQL. Aggregation pipelines are generally resource intensive operations. So if in case your work is satisfied with simple queries, you should use that one at first place.

However, if it is absolute necessary then you can use aggregation pipelines in case you need to fetch the data from the multiple collections.

这篇关于MongoDB Aggregation V/S简单查询性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆