I have a $lookup
stage in an mongodb aggregation framework request that adds an array of related documents to each requested document.
$lookup: {
from: 'cats',
localField: '_id',
foreignField: 'cat',
as: 'cats',
}
So each document in the result has a field with an array like this:
cats: [{ name: "cat7"),{ name: "cat2"), ...]
How can I get each array sorted e.g. by name? Is there an aggregation step for this?
cats: [{ name: "cat2" }),{ name: "cat7" ), ...]