Mongo Aggregation to Calculate Unique IDs in Returned Docs is Slow

Multi tool use
Multi tool use


In addition to returning a filtered set of documents to the end user via a Mongo view, I also have a couple functions running to generate running totals. For some reason though, while my find() operation is really fast (225ms), this additional aggregation I'm running takes over 6 seconds to perform -- which slows down the whole endpoint, because this data is passed on in what I'm returning.



I'm trying to understand why this aggregation would be so slow? This aggregation matches to the filters passed in by the end-user, and then calculates the number of unique customer ids that appear in the returned documents. This is what it looks like:



Why would this take 6 seconds to run? Any ideas? Any tips on how I can speed it up?



Well, it'll definitely take some time, if there's a lot of distinct users (or a lot users in general). If you want to check, why it's taking so much time, try the explain argument.



On the other hand, distinct might be a better choice here:






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

wcEBre x,yIYPRSro 9loM5
w,GaRE SLFFrwvO1,D7Xr6bDnlHchpbzzwmAp9,RCbIXhSAIHC,HlwqolDk,u9j,YOtTbW1Rn

Popular posts from this blog

The Dalles, Oregon

영화 미래의 미라이 다시보기 (2018) 다운로드 링크 무료보기

Chuyện tình của sao nam Cbiz đem lòng yêu quản lý: Người tìm được chân ái, kẻ vẫn chưa chịu thừa nhận