简体   繁体   中英

Get snapshot size on client side - Firestore javascript

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?

The QuerySnapshot object doesn't have an exists property, that one is only available on DocumentSnapshots .

You can either check querySnapshot.empty or querySnapshot.size

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM