r/DatabaseHelp • u/jay-random • Jun 19 '20
MongoDb aggregate with large number of documents?
Hey guys,
I'm using mongodb and trying to do aggregation lookup. The number of documents in the collection which is being used in "from" attribute of $lookup are in thousands. Now this is taking up all the CPU and taking a looot of time to respond.
But if i remove the documents to couple hundreds it's still slow but much much faster than earlier.
Is this normal behaviour for aggregation lookup? Should i think of something else if i have large number of documents?
Please suggest
3
Upvotes
View all comments
Show parent comment
1
u/jay-random Jun 20 '20
Thanks! Actually the aggregation that I'm doing is very simple.
Let me explain the scenario. So there are two collections, one is User and other is Notification. Notification has a field
type. I want to get all the users which have notifications of a particular type. Notification collection has thousands of documents and i have indexed _id and type fields.what do you think is the recommended way of doing this?