簡體   English   中英

是否可以在不在 Firestore 中添加文檔的情況下將子集合添加到集合中?

[英]Is it possible to add a subcollection to a collection without adding document in Firestore?

模型示例

我想為上圖這樣的帖子創建一個數據庫 model。

posts(collection) > categories(document) > c1(collection) > post_id(document) > post_data

在那種情況下,如果我對c1集合執行任何查詢,如whereEqualTowhereLessThan ,它工作正常。

但在另一種情況下,

posts(collection) > all(document) > post_id(collection) > post_data

在那種情況下,我想對all執行查詢,但我不能,因為它是一個文檔。

那么有什么方法可以在不添加文檔或添加虛擬文檔/集合的情況下將子集合添加到集合中,如下所示是唯一的方法嗎?

posts(collection) > all(document) > xyz(collection) > post_id(document) > post_data

需要幫忙:(

現在是不可能的,你只能將文檔添加到一個集合中。 您的解決方案可能是重組您的數據庫。 現在看起來有點奇怪,你雙重保存你的數據。

我建議你這樣做:

POSTS:
     P1:
          category: c1
          data: somedata
     P2:
          category: c1
          data: somedata
     P3:
          category: c2
          data: somedata

之后,您可以執行查詢whereEqualTo("category", c1) ,您將獲得類別 c1 中的所有文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM