Reputation:
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!
Upvotes: 3
Views: 3841
Reputation: 83058
You should use the empty
property, as follows:
//....
if(querySnapshot.empty) {
console.log("nichts");
} else {
//....
Upvotes: 10