I am creating a NodeJS application and I want to sort contacts by last name. The problem is the name part must be saved as one string and when I use the sort function in MongoDB, the defaults are ascending or descending. Is it possible to create a custom sort? For example, if the information is
[
{
_id: "565c9f1ad5015e516ea99b91",
name: "David Li"
},
{
_id: "56642c73b35adedf4fad6c30",
name: "George Chan"
}
]
how can I sort it by the last name?
Currently I am sorting like this:
var options = {
sort: "name"
};
collection.find({}, options, function(err, cursor) {
res.json(cursor);
});