node.js - Lazy loading using nodejs and mongoDB as backend data -


our collection has around 100 million documents. created simple application using nodejs , expressjs limit clause in mongo query . sufficient users of now. in mean time trying implement lazy loading initial page load returns few documents , when user scrolls load further documents. struggling start , how ahead implement it. appreciate suggestions. index.js file

router.get('/users', function(req, res) {   var db = req.db;    var users = db.get('users');     users.find(query, {limit: 10000}, function(e, docs){     res.render('users', {        title: 'users',       'users': docs       });   }); }); 

i remove limit , using skip trying achieve this. please post suggestions

this should help. uses .skip method of .find() cursor. call pagination rather lazy loading.

var itemsperpage = 10;  router.get('/users/:pagenum', function(req, res) {   var db = req.db;    var users = db.get('users');    users.find(query, {skip: (itemsperpage * (pagenum-1)), limit: itemsperpage},function(e, docs){     res.render('users', {        title: 'users',       'users': docs       });   }); }); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -