I've got this firebase cloud function that I've coded to count the number of registered users vs the anynymous users.
// Recalc totals user
exports.recalcTotalUsers = functions.https.onRequest((req, res) => {
var arr = {
anonymous: 0,
registered: 0
};
console.log('starting recalcTotalUsers');
admin.database().ref("users").once("value").then((snapshot) => {
snapshot.forEach(function (uid) {
if (uid.child('/email').val() == ANONYMOUS_STRING) {
arr.anonymous++;
} else {
arr.registered++;
}
console.log(`1. ${arr.anonymous}:${arr.registered}`)
})
});
res.status(200).send(`ok registered: ${arr.registered}, anonymous: ${arr.anonymous}`)
});
When the function returns I get alway anonymous = 0 and registered = 0 event if they have different values... what I am doing wrong?