[英]How to query a Collection after a specific Document in Cloud Firestore with Android?
我具有以下數據庫結構:
Firestore-root
|
--- lists (collection)
|
--- userId1 (document)
| |
| --- userLists (collection)
| |
| --- docKey1 (document)
| | |
| | --- listName: "ListOne"
| | |
| | --- date: January 15, 2018 at 9:56:24 AM UTC+2
| |
| --- docKey2 (document)
| |
| --- listName: "ListTwo"
| |
| --- date: January 15, 2018 at 9:58:12 AM UTC+2
|
--- userId2 (document)
|
--- userLists (collection)
|
--- docKey1 (document)
| |
| --- listName: "ListOne"
| |
| --- date: January 15, 2018 at 9:56:24 AM UTC+2
|
--- docKey3 (document)
|
--- listName: "ListThree"
|
--- date: January 15, 2018 at 9:59:47 AM UTC+2
使用這種數據庫結構,我可以簡單地查詢與特定用戶相對應的所有列表。 但是,如何查詢數據庫以獲取具有特定列表的所有用戶?
在這種情況下,如何獲取所有具有ListOne
作為列表的用戶? 結果應為: userId1
我需要重復數據還是有另一種方法?
編輯:
Firestore-root
|
--- allList
|
--- listId1 (collection)
|
--- userId1 (document)
| |
| --- username: "FirstUser"
| |
| --- //other details
|
--- userId2 (document)
|
--- username: "SecondUser"
|
--- //other details
謝謝!
無法將查詢擴展到多個子集合。 查詢必須包含在單個集合或子集合中。 因此,您猜測需要重復數據才能執行查詢是正確的。
實際上有一個技巧可以完成。 您可以在docKey1
文檔中添加map
,而不是復制數據,如Todd Kerpelman 在此處所述。 您的文檔如下所示:
userLists (collection)
|
--- docKey1 (document)
|
--- listName: "ListOne"
|
--- date: January 15, 2018 at 9:56:24 AM UTC+2
|
--- users
|
--- userId1: true
|
--- userId2: true
因此,您可以查詢該特定文檔以獲取所有用戶ID。 因此,您可以通過這種方式獲得所需的信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.