apache / nano

Nano is now part of Apache CouchDB. Repo moved to https://GitHub.com/apache/couchdb-nano
https://github.com/apache/couchdb-nano
Other
1.13k stars 157 forks source link

Attempting to return simple list of documents, small issue #365

Open treeternity opened 6 years ago

treeternity commented 6 years ago

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});

        }