r/DatabaseHelp • • 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

4 comments sorted by

View all comments

Show parent comment

1

u/BrainJar Jun 20 '20

I recommend external indexing, much like the write-up I linked suggests. If you can’t do that, then bucket based on notification type, to at least collect your types together, as they’re the filter criteria for the aggregation.

1

u/jay-random Jun 20 '20

Thanks!
I'm currently thinking of getting the user ids from the notification collection (with pagination) and then retrieve users.
Whenever i get into this relation hell with nosql i always get lured to RDMS. :D