mu_sa
mu_sa

Reputation: 2725

Sorting would not work

I have written a sorting function but it would not work. I have no idea where am i going wrong.The code below is suppose to sort picture on the basis of points

models.Picture.find().sort({points:-1}).all(function (err, pics){
if(err) {
    throw err;
}
pics.forEach(function(pic) {
    pictures.push(pic);
})
});

Upvotes: 0

Views: 43

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 311835

You should be calling run and not all. all invokes the $all operator which is an array matching operator. As in:

models.Picture.find().sort({points:-1}).run(function (err, pics){

Upvotes: 1

Related Questions