【问题标题】:How can I query the length of my array with firestore?如何使用 firestore 查询数组的长度?
【发布时间】:2022-01-03 19:11:17
【问题描述】:

这是我的目标

readUserIDS:[
    0: ID1
    1:ID2
]

readUserIDS:[
    0: ID1
]

我只想渲染具有 1 个 ID 的数组,但我不知道如何使用 firestore 查询我的数组。基本上,我只想找到一个 ID 的 array.length

  const notification = () => {
    channelsRef
      .where('channelID', '==', item.id)
      .get()
      .then((querySnapshot) => {
        querySnapshot.forEach((doc) => {
          doc.ref
            .collection('thread')
            .where('senderID', '==', item.participants[0].id)
            .where('readUserIDs.2', '>', '')
            .get()
            .then((querySnapshot) => {
              console.log('size', querySnapshot.size);
              querySnapshot.forEach((thread) => {
                let data = querySnapshot.size;
                console.log('data', data);
              });
            });
        });
      });
  };

【问题讨论】:

    标签: react-native google-cloud-firestore


    【解决方案1】:
      const notification = () => {
        channelsRef
          .where('channelID', '==', item.id)
          .get()
          .then((querySnapshot) => {
            querySnapshot.forEach((doc) => {
              doc.ref
                .collection('thread')
                .where('senderID', '==', item.participants[0].id)
                .where('readUserIDs.2', '>', '')
                .get()
                .then((querySnapshot) => {
                  return querySnapshot.size;
                });
            });
          });
      };
    

    【讨论】:

    • @Xwingoga06 您能否确认答案是否有帮助?如果是,您可以投票或接受答案吗?这将真正帮助社区。​​span>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 2020-11-21
    • 2021-08-06
    • 2021-11-26
    • 2019-04-26
    • 1970-01-01
    相关资源
    最近更新 更多