【问题标题】:How can i get multiple documents from the firestore如何从 Firestore 获取多个文档
【发布时间】:2019-10-15 12:22:13
【问题描述】:

您好,我想从 firestore 获取多个文档。

var docBookingRef = firestore().collection('timeSlot');
docData.forEach((item) => {
    docBookingRef.where('docId', '==', item);
});
docBookingRef.get().then((doc) => {
    doc.forEach(function(docV) {
        console.log("Slot data", docV.data());

    });
})

docData 包含所有列表的 id。 我没有从上面的代码中得到任何列表。

【问题讨论】:

    标签: javascript react-native google-cloud-firestore


    【解决方案1】:

    我几乎没有使用过 React,也从未使用过 Firebase,但是在使用 where 之后,您可能会立即想要使用 get()where 返回一个新的查询对象,get() 检索信息,如 @ 987654321@澄清)

    docData.forEach((item)=>{
       firestore().collection('timeSlot')
                  .where('docId','==', item)
                  .get()
                  .then(function(doc) {
                         doc.forEach(function(docV) {
                             console.log("Slot data", docV.data());
                         });
                  });
    });
    

    【讨论】:

    • 几乎! where(...) 调用返回一个新的 Query 对象,因此您需要执行 docBookingRef.where('docId','==',item).get().then(...
    • 我对此有疑问,它总是向我发送相同的数据。插槽数据总是相同而不是不同
    • @SShah 答案的确切代码(纠正拼写错误,如果有的话)在控制台上总是打印相同的数据?如果是这样,那么问题可能出在其他地方
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    • 2023-01-19
    • 2018-09-03
    • 2018-08-24
    • 1970-01-01
    相关资源
    最近更新 更多