I want to perform a Firestore query in a JavaScript function, but I'm having some difficulties with promises.
Let's say I want to get the document ID from a user. So I have created this JavaScript function:
function getUid(email) {
db.collection("users").where("email", "==", email)
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
return doc.id;
});
})
.catch(function(error) {
return error;
});
}
Now when I call the function res.send(getUid("[email protected]")), it returns undefined.
Which is the correct syntax to wait until the Firestore query finsished?
resand where are you calling it?res.sendis just for sending a response in Google cloud functions.