server.get('/getlist', function (req, res, next) {
db.collection('lists',function(error, collection) {
var gets = [];
var cursor = collection.find({status: 1});
var i = 0;
cursor.each(function (err, docs) {
console.log(docs);
gets[i] = docs;
i = i + 1;
});
res.send(gets);
});
return next();
});
It can log out correctly, but the website "http://127.0.0.1:8080/getlist" result is empty "[]".
How to make cursor.each run in sequence every source code line? Or is there any better solution?