I am fetching docs length from collection logs. It works absolutely fine if there are documents in the collection, but it doesnt give any response when collection is empty. I want it to return 0 or null in this case.
My code::
firebase.firestore().collection('logs')
.where("date" , "==" , show_year_month_date)
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc=> {
console.log(doc.id, " => ", doc.data());
alert(querySnapshot.docs.length); // It doesnt goes here if collection is empty
console.log(querySnapshot.docs.length);
if(querySnapshot.docs.length==null){
console.log("its null"); // It doesnt goes here if collection is empty
}
if(querySnapshot.docs.length>0){
console.log("entry found");
}
if(!querySnapshot.docs.length){
console.log("no entry");
alert("no entry"); // It doesnt goes here if collection is empty
this.sendLogs();
}
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
alert("error no document found"); // It doesnt goes here if collection is empty
})
}