Du kan ændre dit $project
for også at omforme outputtet for at give den struktur, du leder efter:
Story.aggregate([
{ $unwind: "$comments" },
{ $project: {
author: '$comments.author',
content: '$comments.content',
_id: '$comments._id'
}},
{ $sort: {author: -1}}
], function (err, result) { ...
Output:
[ { _id: 541c2776149002af52ed3c4a,
author: 'B author',
content: '2 Content' },
{ _id: 541c2776149002af52ed3c4b,
author: 'A author',
content: '1 Content' } ]