简体   繁体   English

使用 Dart/Flutter 查询包含保存在 Cloud Firestore 中的字符串的 Map

[英]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 :如果categoryproduits数组项中的唯一值,您可以使用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.

相关问题 Cloud Firestore Firebase Collection ref 上的 IN 查询是否有 Flutter/Dart 等价物? - Is there a Flutter/Dart equivalent for the IN query on a Cloud Firestore Firebase Collection ref? 如何使用 flutter 和 dart 从 Cloud Firestore 检索特定数据? - how to retrieve specific data from Cloud Firestore using flutter and dart? 如何将 map 数据添加到 flutter 中的 Cloud firestore? - how to add map data to cloud firestore in flutter? 从 Flutter 中的 Firestore 查询单个文档(cloud_firestore Plugin) - Query a single document from Firestore in Flutter (cloud_firestore Plugin) Flutter Cloud Firestore:错误:参数类型“对象? Function()' 无法分配给参数类型 'Map<string, dynamic> '</string,> - Flutter Cloud Firestore: error: The argument type 'Object? Function()' can't be assigned to the parameter type 'Map<String, dynamic>' 如何使用嵌套的 map 字段为带有 flutter 的云 Firestore 创建用户 model? - How to create user model with nested map field for cloud firestore with flutter? Firestore 数据库未更新(颤振/飞镖) - Firestore Database not updating (flutter/dart) Flutter / Dart Firestore 响应从 Array 中抓取 map 项目数据而不迭代整个事物? - Flutter / Dart Firestore response grab map item data from Array without iterating the entire thing? 在 Firestore Cloud 中设置查询 - Seting a Query in Firestore Cloud Flutter:Cloud Firestore Firestore 组件不存在 - Flutter: Cloud Firestore Firestore component is not present
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM