'How to use mongodb lookup aggregation with sort?

From my connection_dags_archived collection, the following lookup works, giving me the joined items in an array: enter image description here

But when I wish to move it into a pipeline to add sorting, it fails:

enter image description here

And when even the sorting is removed, the array is empty:

enter image description here

How do I add sorting on the join?



Solution 1:[1]

The problem is that your "steps_archived" collection does not have index on "timestamp" field, so the query times out because it takes too much time to execute. Add index to that field and increase "execution timeout" option and try again.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tomov Nenad