简体   繁体   English

如何通过子数组中项目的 ID 获取 firestore 文档

[英]How can I fetch firestore documents by the Id of an item in it's sub array

First of all sorry if the title is not very explicit (I don't speak English very well).如果标题不是很明确(我的英语说得不太好),首先抱歉。

I have a Firebase firestore collection.我有一个 Firebase firestore 集合。 In this collection all the documents have an array.在这个集合中,所有文档都有一个数组。

Here is an example of how the documents are structured:以下是文档结构的示例:

  • Document文档
    • Id ID

    • Array大批

      • Item1项目1

        • Item1Id Item1Id
      • Item2项目2

        • Item2Id Item2Id

I have the Id of an item of the array (eg 'Item1Id') and I want to fetch all the documents in which the array contains an item with this Id.我有数组项的 ID(例如“Item1Id”),我想获取数组中包含具有此 ID 的项的所有文档。

How can I do that?我怎样才能做到这一点?

You can't.你不能。 This page explains how to perform queries on Firestore: https://firebase.google.com/docs/firestore/query-data/queries此页面解释了如何在 Firestore 上执行查询: https://firebase.google.com/docs/firestore/query-data/queries

array-contains will return documents that have an array containing the itemId , but it doesn't work with nested data. array-contains将返回具有包含itemId的数组的文档,但它不适用于嵌套数据。

A solution would be to create an itemIds array in your document that simply contains the list of itemIds, and perform the query on that field.一种解决方案是在您的文档中创建一个仅包含 itemId 列表的itemIds数组,然后对该字段执行查询。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从一组 ID 查询 firestore 中的文档 - Query documents in firestore from an array of ID's 如何插入具有唯一 GUID 的新 Firestore 集合文档? - How can I insert new Firestore collection documents with unique GUID for an id? 如何在 Firestore 的子集合中查询文档? - How to Query for documents in a sub collection in Firestore? 如何使用 flutter 从 Firestore 获取子集合? - How do I fetch sub collection from firestore using flutter? 如何根据 Cloud Firestore 中的主集合字段和子集合字段查询子集合中的文档? - How to query documents from a sub-collection, based on a main collection's field and a sub-collection's fields in cloud firestore? Firestore - 如何在删除他的帐户时从他自己创建的所有文档中删除用户 ID? - Firestore - how do I remove user's ID from all the documents he's created himself when deleting his account? Firestore - 我可以像收集列表一样获取所有文档 ID 吗? - Firestore - Can I get all documents ID just like collection list? 如何计算 swift 中 firestore 查询的文档数? - How can I count the documents from a firestore query in swift? 在 Google Cloud Firestore 的子集合中更新依赖于多个文档的字段时,如何避免竞争条件? - How can I avoid a race condition when updating a field that's dependent multiple documents in a subcollection in Google cloud firestore? 如何从 Firestore 获取文档 ID 列表 - How do I get a list of document ID’s from Firestore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM