I want to check if the querySnapShot is empty. How can I do this?
Here is my code:
function getOrders(userid) {
db.collection("users").doc(userid).collection("bestellungen").get().then(function(querySnapshot) {
if(querySnapshot is empty) {
console.log("nichts");
}
else {
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
});
}
});
}
Looking forward to your answers!
I want to check if the querySnapShot is empty. How can I do this?
Here is my code:
function getOrders(userid) {
db.collection("users").doc(userid).collection("bestellungen").get().then(function(querySnapshot) {
if(querySnapshot is empty) {
console.log("nichts");
}
else {
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
});
}
});
}
Looking forward to your answers!
Share Improve this question edited Mar 19, 2023 at 14:43 Renaud Tarnec 83.2k10 gold badges98 silver badges129 bronze badges Recognized by Google Cloud Collective asked May 22, 2020 at 12:56 user12304080user123040801 Answer
Reset to default 10You should use the empty
property, as follows:
//....
if(querySnapshot.empty) {
console.log("nichts");
} else {
//....