[英]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:以下是文档结构的示例:
Id ID
Array大批
Item1项目1
Item2项目2
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.