当前位置: 动力学知识库 > 问答 > 编程问答 >

express - Pagination sorting

问题描述:

I have pagination mechanism built, and it works by sorting id's and returning limit number of results.

 Video.find(condition, {})

.limit(req.body.limit)

.sort(sort)

.exec(function (err, videos) {

if (err) {

return err;

}

var first = '';

var last = '';

// If no scroll

if (req.body.type == '') {

if (videos.length > 0) {

first = videos[0]._id;

last = videos[videos.length - 1]._id;

}

}

// If scroll happend req.body.type is next

else if (req.body.type == 'next') {

if (videos.length > 0) {

first = videos[0]._id;

last = videos[videos.length - 1]._id;

}

}

res.status(200).send({message: 'listOk', videos: videos, firstID: first, lastID: last});

});

Sort is:

var sort = {_id: 1, dtCreated: -1};

And so far dtCreated : -1 doesn't work.

How can I return limit number of results sorted by id's and dateCreated? Can I sort my videos result array?

分享给朋友:
您可能感兴趣的文章:
随机阅读: