【问题标题】:How to handle nested collection query in cloud flutter firestore?如何处理 Cloud Flutter Firestore 中的嵌套集合查询?
【发布时间】:2020-08-27 20:59:45
【问题描述】:

如果有这样的收藏

Shop(Collection):
     -shopId(Document)
         -name
         -adresse
         -itemSold (Nested Collection)
             -itemId
                 -....
                 -....

我如何在颤振中编写一个查询,它将只返回在 itemSold 集合中具有特定 itemId 的商店。

这要花很多时间阅读吗?

你如何处理你身边的那种树我在 noSQL 数据库中很新。我使用传统的数据库。

【问题讨论】:

  • 您好,如果您认为某个答案解决了问题,请单击绿色复选标记将其标记为“已接受”。这有助于将注意力集中在仍然没有答案的旧 SO。
  • 这能回答你的问题吗? Firestore query subcollections

标签: firebase flutter google-cloud-firestore


【解决方案1】:

您可以使用 .where 方法。

在你的情况下是这样的:

DocumentReference shopInstance = Firestore.instance
        .collection('shops')
        .document('shopsID'):
await shopInstance
      .collection('itemSold')
      .where('itemID', isEqualTo: 'someId')
      .getDocuments()
      .then()...

【讨论】:

  • 您好 Itiel,感谢您的回答!它给了我一个更好的主意。你知道这种设置是好是坏吗?我认为文档会更小,但会增加阅读次数。
猜你喜欢
  • 1970-01-01
  • 2021-09-29
  • 2018-11-26
  • 1970-01-01
  • 2019-12-03
  • 2020-04-29
  • 1970-01-01
  • 2020-10-10
  • 1970-01-01
相关资源
最近更新 更多