I've an aggregation pipeline that is getting quite slow. Let's say my documents looks like:
{
value1,
value2,
}
and that they are indexed on both fields.
My pipeline is:
collection.aggregate([
{
$match: { value1: someVar },
},
{
$sort: { value2: 1 },
},
{
$limit: 5,
},
], cb);
The issue is that there's quite a few documents matching (~10k) and that I'm losing the index advantage on the second step of the pipeline. Is there a good way to improve that that would leverage the indexing for both match and sort?