doing a mongo DB lookup, intending to save result in a scoped variable.
var users = ['kat'];
collection.find({key: key}, function(err, doc) {
if (doc) {
var firstEntry = doc[0];
users = firstEntry.users;
users.push('jack');
} else {
console.log("DB ERROR: cannot find: " + key);
}
});
console.log(users); // Why does this return only Kat, and Jack is not appended?
Thanks!