I've got a problem while programming some functions for Firebase functions. I want to find the User with the highest value stored in PFM and save his name in a Variable but the Variable does not change. What am I doing wrong?
Here is my Code:
var highestPFM = 0;
var userToSend = "";
db.collection("users").get().then((snapshot) => {
snapshot.forEach((doc) => {
var data = doc.data();
if(highestPFM > data["pfm"]){
highestPFM = data["pfm"];
userToSend = doc.id;
}
});
console.log(prefixSendBottle + "User with highest PFM: " + userToSend);
return userToSend;
}).catch((err) => {
response.send(err);
console.log(err);
});