1.cmd输入limit为字段 skip为下标

  1. //limit(2) 只会获取两条数据
  2. db.top250.find().limit(2)
  3. //skip() 下标
  4. db.top250.find().skip(1).limit(2)

2.前端处理limit和下标

  1. http://localhost:8080/top250?start=0&count=5;
  2. start-->为下标
  3. count-->为限制

3.index.js

  1. router.get("/top250",async ctx=>{
  2. console.log(ctx.query)
  3. var {start,count} = ctx.query
  4. console.log(start)
  5. if(start==undefined){
  6. start = 0
  7. }
  8. if(count == undefined){
  9. count = 5
  10. }
  11. var data = await Top250Model.find({}).skip(Number(start)).limit(Number(count));
  12. ctx.body = {
  13. data,
  14. code:200
  15. }
  16. })