![](/img/trans.png)
[英]how to where query a collectionGroup in firestore flutter?
[英]Is it possible to access a parent doc field over a firestore collectionGroup query
我的問題不是關於在您擁有文檔快照時訪問父文檔的字段。
我正在嘗試執行一個查詢,該查詢必須訪問父文檔的字段,例如,使用此 NoSQL 結構:
(C) users/
(D) userId/
-premium: false
-random: uuid.v4 string
(C) privateData/
(D) userPrivateData/
-notificationsToken: "9329e48329"
...
如果我想運行一個從非高級用戶那里獲取 N 個隨機 notificationsTokens 的計划任務,最簡單的 go 方法是執行“collectionGroup”查詢,如下所示:
firestore
.collectionGroup("privateData")
.where("random", Math.random() < 0.5 ? "<=" : ">=", randomId)
.where("premium", "==", false)
.orderBy("random")
.orderBy("notificationsToken");
但是,“隨機”和“高級”字段對應於父文檔......
是否可以訪問 firestore collectionGroup 查詢中的父文檔字段?
不,這是不可能的, where()
子句只能應用於每個privateData
子集合中的文檔。
一種解決方案是復制子項中的字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.