admin管理员组

文章数量:1314554

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 badges
Add a ment  | 

1 Answer 1

Reset to default 9

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

本文标签: firebaseGet snapshot size on client sideFirestore javascriptStack Overflow