I am querying firestore for some results. But before running forEach loop on docs, i want to know if there are any docs in collection snapshot, and snapshot.exist()
always giving false even if there are docs in it.
db.collection("users").where("mobile_no", '==', mobileToCheck).get().then(function(querySnapshot){
if (querySnapshot.exists) { \\THIS ALWAYS RETURNING FALSE
querySnapshot.forEach(doc => {
console.log(doc.data());
});
console.log(mobileToCheck + "Exist In DB");
}else{
console.log(mobileToCheck + "Do Not Exist In DB");
}
});
How would i know if there are any results?
I am querying firestore for some results. But before running forEach loop on docs, i want to know if there are any docs in collection snapshot, and snapshot.exist()
always giving false even if there are docs in it.
db.collection("users").where("mobile_no", '==', mobileToCheck).get().then(function(querySnapshot){
if (querySnapshot.exists) { \\THIS ALWAYS RETURNING FALSE
querySnapshot.forEach(doc => {
console.log(doc.data());
});
console.log(mobileToCheck + "Exist In DB");
}else{
console.log(mobileToCheck + "Do Not Exist In DB");
}
});
How would i know if there are any results?
Share Improve this question asked Oct 7, 2017 at 6:56 Noman AliNoman Ali 3,34013 gold badges47 silver badges79 bronze badges1 Answer
Reset to default 9The QuerySnapshot object doesn't have an exists
property, that one is only available on DocumentSnapshots.
You can either check querySnapshot.empty
or querySnapshot.size