【问题标题】:Flutter: How to query docs in firestore based a field in an array?Flutter:如何根据数组中的字段查询 Firestore 中的文档?
【发布时间】:2021-11-12 15:50:16
【问题描述】:

我需要根据 firestore 文档中自定义对象列表中的字段查询文档。以下是整个文档的样子:

  String id;
  List<AlgorandTransactionWalletData> algorandTransactionWalletData;
  AlgorandTransactionType algorandTransactionType;
  String itemId;
  int creationTimeInMilliseconds;

这是 AlgorandTransactionWalletData 的样子:

List<AlgorandTransactionId> algorandTransactionIds;
String address;
AlgorandAddressType algorandAddressType;
List<CurrencyId> currencyIds;

我需要获取包含我在 algorandTransactionWalletData 列表中查询的地址的整个 firestore 文档。这可以吗?

【问题讨论】:

  • 发布您的 Firestore 屏幕截图,显示您需要的文档及其父集合。
  • 请编辑您的问题并将您的数据库结构添加为屏幕截图,并指明您要执行查询的确切字段。请回复@AlexMamo
  • @AlexMamo 我正在尝试根据整个文档中的 algorandTransactionWalletData 列表字段中的 AlgorandTransactionWalletData 数据模型中的地址字段进行查询(抱歉,如果这令人困惑)。如果列表中的一个实例具有我要查找的地址,我想返回整个文档。

标签: flutter google-cloud-firestore


【解决方案1】:

好的,如果您想获取具有该地址的所有文档(在集合中),您可以使用 where 条件查询集合。这应该获取与 where 条件匹配的所有文档。

以下是您可以使用的示例。将 COLLECTION_NAME 替换为文档集合的名称。

FirebaseFirestore.instance
  .collection('COLLECTION_NAME')
  .where('address', isEqualTo: queryAddress);
// where queryAddress is the address you want to find.

【讨论】:

  • 这个答案被标记为低质量,请提供更多支持信息和解释来改进答案
  • 谢谢,我已经更新了答案并提供了更多解释。现在还好吗?
  • 是的,这样好多了,下次注意。我们努力使网站上的每个答案和问题都尽可能清晰和翔实,让遇到相同问题的人能够轻松理解问题原因和解决方案
猜你喜欢
  • 1970-01-01
  • 2020-06-14
  • 2019-11-27
  • 1970-01-01
  • 2015-06-22
  • 2021-12-04
  • 2019-03-21
  • 2020-07-03
  • 2018-06-04
相关资源
最近更新 更多