I would like to sort a populated Document from the collection i fetch, i get an error requesting it.
Let\'s admit a Document Group
(Group) and \'Member\
The following worked for me in Mongoose v5.0.5:
Schedule.find({})
.populate({path: 'eventComments', options: {sort:{"commentDate": "descending"}}})
.exec(function(err, result) {
if (err) {
throw err
}
else {
return res.json(result);
}
});
P.S. The key difference between this example and the Kitten example is that commentDate is in quotes, whereas Date (in the Kitten example) is not. This alteration may be necessary for some of you. Hope this helps.