http://www.ttlsa.com/mongodb/mongodb-sort-limit-skip-usage/
1. Sort is used for sorting. Sort ({"Field": 1})
2. Skip skips how many results
3, limit each query returns the maximum number of results;
The use of the project is relatively good;
Record again;
The front desk passed, page parameters, according to the page parameter is determined to be the first few pages;
1 function (CB) {user.find (query). Skip (Page *). EXEC (function(err, items) {CB (err, items),});})
1Router.get ('/api/users/search/:key/:p age ',function(req, res) {2 if(_.isempty (Req.params.key)) {Res.json ({items:NULL});return; }3 4 varKey =Urlencode.decode (req.params.key);5 varpage =parseint (req.params.page);6 if(!page) page = 0;7 varquery = {Nickname:NewREGEXP (Key, "I")};8 Thunk.all ([9Thunkfunction(CB) {user.find (query). Skip (Page *).. EXEC (function(err, items) {CB (err, items);}); }),TenThunkfunction(CB) {user.count (query). EXEC (function(Err, count) {CB (err, count);}); }) One])(function(CB, results) { ARes.json ({items:results[0], total:results[1]}); - }); -});
This is how the page page is usually paged
Careful analysis, should be click on which page, through the JS to get the number of clicks, the number of pages through Ajax or direct jump to the background, back to the background data, rendering to the front;
Skip above refers to skipping the page*40 bar,
Limit returns 40,
For example, page fifth, skip 4*40, showing 161 to 200 of the content;
MongoDB sort limit and skip usage