謝謝各位了。這里的問題是沒有找到C接口
的分頁查詢的操作。
英文太渣,在mongoDB的網(wǎng)站上沒有發(fā)現(xiàn)分頁相關(guān)的。
http://api.mongodb.com/c/current/tutorial.html
增刪查改和計數(shù)都有,就是沒有發(fā)現(xiàn)分頁操作的。。。
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
mongodb
Like 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