【问题标题】:firestore : why retrieved data is not getting into an variable in cloud functionsfirestore:为什么检索到的数据没有进入云函数中的变量
【发布时间】:2018-03-21 08:44:02
【问题描述】:

我从 Firestore 中检索了数据。当检索到的数据存储到变量中时,我得到 [object object]。我不明白为什么会发生这种情况?

我的代码是

 var dbref = db1.collection('deyaPayUsers').doc(sendauthid).collection('Split').doc(sendauthid).collection('SentInvitations').doc(senderautoid);
         var fulldoc = dbref.get()
                            .then(doc => {
                            if(!doc.exists){
                            console.log('No such document');
                            }else{
                            console.log('Document data :',doc.data());
                                d1 = doc.data();// here I am not getting the data
                                console.log("d1 is"+d1);
}
});

【问题讨论】:

标签: firebase google-cloud-functions google-cloud-firestore


【解决方案1】:

我不知道你真正想要实现什么,因为你共享了不完整的代码。不过我希望下面的代码对您有所帮助。

const db = firebase.firestore()
let self = this;
 db.collection("User")
        .get()
        .then(function (querySnapshot) {
          if (querySnapshot.size > 0) {
            querySnapshot.forEach((result) => {
              let data = result.data();
              data.id = result.id;
             console.log(data)
            })
          } else {
            console.log("no data found")
          }
        }
        );

【讨论】:

  • 我正在使用云功能
猜你喜欢
  • 1970-01-01
  • 2019-11-20
  • 1970-01-01
  • 1970-01-01
  • 2020-03-04
  • 2019-09-05
  • 1970-01-01
  • 2016-05-04
  • 2021-06-02
相关资源
最近更新 更多