数据库 - MongoDB C Driver如何进行分页?
为情所困
为情所困 2017-05-02 09:20:49
0
3
660

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

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

为情所困
为情所困

reply all(3)
漂亮男人

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
洪涛

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

滿天的星座

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template