So here is the basic idea on how my pipeline works:
$lookup to do a JOIN on users and their respective comments, the comments’ array is named “comments”
$project the size of the “comments” array for each JOINed document, the field is called “count”
$sort the documents by count in descending order
$limit to 20 documents
But this actually takes WAY too much time to execute, both in Compass and in the npm tests, causing a timeout even if it’s set for 200 seconds. Is there a more efficient way to build the pipeline? I’ve been stuck in this test for 2 hours now.