【问题标题】:Firebase collection query on multiple documents checkFirebase 对多个文档的集合查询检查
【发布时间】:2018-02-15 09:51:06
【问题描述】:

是否可以在 firebase firestore 中获取有关多个可用文档的信息,或者使用我们正在使用 react native 的 where 查询。

userRef.where('number', '==', '123')
    .where('number', '==', '1234')
    .get()
    .then(r =>{

      r.forEach(n => console.log(n))

    });

是否有可能得到这两个文件的响应?

如果我在工作正常的情况下使用 like single,我如何将相同的东西用于嵌套文档比较?

【问题讨论】:

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


    【解决方案1】:

    如果我正确理解您的用例,您希望获得两个用户,其中用户一的号码为 123,用户二的号码为 1234。

    据我了解,Firestore 目前无法进行此类查询,但您可以将它们拆分为两个查询并合并结果。

    const userOne = userRef.where('number', '==', '123').get();
    const userTwo = userRef.where('number', '==', '1234').get();
    
    Promise.all([userOne, userTwo])
    .then(result => {
        /*
        * expected output: Array [QuerySnapshot, QuerySnapshot]
        * First QuerySnapshot is result from userOne "where"
        * Second QuerySnapshot is result from UserTwo "where"
        */
    
        const userOneResult = result[0];
        const userTwoResult = result[1];
    
        if (userOneResult.empty === false && userTwoResult.empty === false) {
            // Get both your users here
        }
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-24
      • 1970-01-01
      • 1970-01-01
      • 2021-09-05
      • 2023-01-19
      • 1970-01-01
      • 2020-03-10
      相关资源
      最近更新 更多