[英]Query a Map containing a string saved in Cloud Firestore with Dart/Flutter
I've a problem with a query condition.我的查询条件有问题。 I would like to query a string inside an array that's also inside a map. I manage to receive the information complet without the where condition but when I do this condition I've an error.
我想查询一个数组中的字符串,该数组也在 map 中。我设法在没有 where 条件的情况下接收到完整的信息,但是当我执行此条件时出现错误。
My function to retrieve all information我的function取回所有信息
My array with a map inside我的数组里面有一个 map
If category
is the only value inside the produits
array items, you can check for its existence with array-contains
:如果
category
是produits
数组项中的唯一值,您可以使用array-contains
检查它是否存在:
collectionRef.where('produits', arrayContains({ 'categorie': 'Alimentation' }))
If there are more properties for the array item, you will need to specify all of them in the call to arrayContains
.如果数组项有更多属性,则需要在调用
arrayContains
时指定所有属性。 There is no way to query for a subset of the array item.无法查询数组项的子集。
In such cases, a common workaround is to add a extra array field to the document with just the property values you want to query for.在这种情况下,一种常见的解决方法是向文档添加一个额外的数组字段,其中仅包含您要查询的属性值。 For example:
例如:
produitsCategories: ['Alimentation', '...']
With that field in place you can then query it with:有了该字段,您就可以使用以下方式查询它:
collectionRef.where('produitsCategories', arrayContains('Alimentation'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.