【问题标题】:react-redux-firebase - How to query documents from Firestore using an array of ID's?react-redux-firebase - 如何使用 ID 数组从 Firestore 查询文档?
【发布时间】:2020-07-22 14:12:53
【问题描述】:

我有一个文档 ID 数组。我想使用数组中的 ID 从 firestore 获取这些文档。换句话说,我需要遍历 ID 数组并使用相应的 ID 查询每个文档。

所以目前这就是我的查询方式。我正在查询“属性”集合中的所有文档。

export default compose(
  connect(mapStateToProps, mapDispatchToProps),
  firestoreConnect((props) => {

      if (!props.auth.uid) {
        props.history.push('/signin')
        return []
      }

      return [


        {
          collection: 'Properties',

        },
        {
          collection: 'Properties',
          doc: propid
      },

        {
          collection: 'Partners',
          doc: props.auth.uid,
          subcollections: [{
              collection: 'MyInvites',

            },


          ]
        },
      {
        collection: 'Partners',
        doc: props.auth.uid,
        subcollections: [{
           collection: 'ReceivedInvites',
          }
        ]
      },
      {
        collection: 'Partners',
        doc: props.auth.uid,

      },

      ]


    }
  )

目标是通过 ID 从“Properties”集合中获取特定文档。我要查询的文档的 ID 在一个数组中。

例如

let idArray=[doc0id,doc1id,doc2id,doc3id,....docnid]

有没有办法做到这一点?

【问题讨论】:

    标签: reactjs firebase google-cloud-firestore react-redux-firebase redux-firestore


    【解决方案1】:

    您所描述的是in query

    因此,对于最多 10 个文档 ID,您可以这样做:

    myCollection.where(firestore.FieldPath.documentId(), 'in', ["123","456","789"])
    

    【讨论】:

      猜你喜欢
      • 2019-04-20
      • 2018-07-06
      • 2021-10-22
      • 2021-04-28
      • 1970-01-01
      • 1970-01-01
      • 2019-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多