最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to check if querySnapshot is empty from firestore - Stack Overflow

programmeradmin1浏览0评论

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!

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!

Share Improve this question edited Mar 19, 2023 at 14:43 Renaud Tarnec 83.2k10 gold badges98 silver badges129 bronze badges Recognized by Google Cloud Collective asked May 22, 2020 at 12:56 user12304080user12304080
Add a ment  | 

1 Answer 1

Reset to default 10

You should use the empty property, as follows:

//....
if(querySnapshot.empty) {
  console.log("nichts");
} else {
//....
发布评论

评论列表(0)

  1. 暂无评论