Attempting to return simple list of documents, small issue
treeternity opened this issue · comments
Hi there, I am attempting to return a small list of objects (checkins_each), but checkins_each is always returning [] an empty list even though the console.log clearly shows that a bunch of json entries are appended. How do I resolve this?
// return data
var checkins = nano.use(settings.COUCHDB_PREFIX+'checkins');
var checkins_each = [];
checkins.list(function(err, body) {
if (!err) {
console.log('hi proximity loop')
body.rows.forEach(function(doc) {
console.log(doc.id);
checkins.get(doc.id, function(err,jsondoc) {
console.log(JSON.stringify(jsondoc));
if (jsondoc.profile_id != profile_id) {
console.log('appending checkin');
checkins_each.push(jsondoc);
}
});
});
res.send({status: 'proximity', checkins: checkins_each});
} else {
console.log("error", err);
res.send({status: 'fail', error: err});
}