search

Home  >  Q&A  >  body text

数据库 - MongoDB C Driver如何进行分页?

谢谢各位了。这里的问题是没有找到C接口的分页查询的操作。

英文太渣,在mongoDB的网站上没有发现分页相关的。
http://api.mongodb.com/c/current/tutorial.html
增删查改和计数都有,就是没有发现分页操作的。。。

为情所困为情所困2754 days ago656

reply all(3)I'll reply

  • 漂亮男人

    漂亮男人2017-05-02 09:22:49

    The conventional method is:

    db.users.find().skip(pagesize*(n-1)).limit(pagesize)
    

    There is also a way with better performance:

    db.users.find().limit(pageSize); //第一页
    last_id = ... //把最后一个_id存下来
    
    
    users = db.users.find({'_id'> last_id}). limit(10); //第二页
    last_id = ... //更新last_id

    reply
    0
  • PHP中文网

    PHP中文网2017-05-02 09:22:49

    mongodbLike other databases, you can query the corresponding number of data for paging operations. The official documents also have corresponding instructions, such as mongodb.limit and mongodb.skip. Or you can refer to this Chinese description limit.skip. Hope it helps you

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-02 09:22:49

    xxxx.find({'xxx':'xxx'},function(err,rs){

    res.json(rs);

    }).limit(listnum).sort({'id':-1}).skip((pagenum-1)*listnum);

    //listnum is the number of records on a page and pagenum is the page number

    reply
    0
  • Cancelreply