我的数据库结构如下(为了解决这个问题而进行了简化):
Collection: item_A
-> Document: params = {someParameter: "value"}
-> Document: user_01
-> Sub-collection: orders
-> Document: order_AA = {type: "A1", address: {pincode: "000000", city:"Paris"}
-> Document: order_AB = {type: "A2", address: {pincode: "111111", city:"London"}
...
-> Document: user_02
-> Sub-collection: orders
-> Document: order_AC = {type: "A1", address: {pincode: "222222", city:"Berlin"}
-> Document: order_AD = {type: "A1", address: {pincode: "333333", city:"Paris"}
...
Collection: item_B
-> Document: params = {someParameter: "value"}
-> Document: user_01
-> Sub-collection: orders
-> Document: order_BA = {type: "B1", address: {pincode: "000000", city:"Paris"}
-> Document: order_BB = {type: "B2", address: {pincode: "111111", city:"London"}
...
-> Document: user_02
-> Sub-collection: orders
-> Document: order_BC = {type: "B1", address: {pincode: "222222", city:"Berlin"}
-> Document: order_BD = {type: "B2", address: {pincode: "333333", city:"Paris"}
...
我想做的事:获取列表all用户指定的集合(项目)的所有用户的订单。
(请注意,“用户”文档的数量随着时间的推移而变化,子集合中“订单”文档的数量也是如此。“项目”的数量是恒定的〜10,所以我希望避免手动编码用于处理它们中的每一个)
用更多的话来说...
用户应输入项目类型(例如 item_A 或 item_B)。
此外,用户可以指定所需的城市(例如巴黎)。
现在我想查询 FireStore 以查找具有匹配城市的特定商品类型的所有订单。
我怎样才能以最短的步骤(最少的查询)做到这一点?
我可以用吗“集合组查询” https://firebase.google.com/docs/firestore/query-data/queries#collection-group-query为了这?我尝试过玩弄这个,但我不确定我是如何理解的。如何限制查询在指定集合(例如 item_A)上运行,而不是在所有可用集合(item_A、item_B)上运行。我是否需要为每个项目(例如orders_item_A)以不同的方式重命名子集合,以有选择地使用集合组查询?