亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我可以構建一個子集合嗎?(消防站)

我可以構建一個子集合嗎?(消防站)

慕村225694 2022-12-29 15:53:36
我試圖弄清楚如何在 Firestore 的以下目錄中構建一個新的子集合(紅色圓圈):目錄:“課程/{userID}/{courseID}”courseID 是在“userID”文檔中創建子集合時隨機生成的 ID。不幸的是,我能夠使用 .set() 運行的代碼不會創建新的子集合,而只是更新當前文檔。是否有可用于在文檔中創建新集合的函數?代碼:export const createCourse = (course) => {        (...)    //firestore.collection("courses").doc(authorId).set({   <---This commented out line updates the document, yet I'm trying to construct a new sub-collection inside this document, not just change fields inside of it.     firestore.collection("courses").doc(authorId).add({     <--- This gives me an error stating " firestore.collection(...).doc(...).add is not a function ".   I am trying to figure out what is the correct syntax for this intended action.        ...course,        authorUID: authorId,        courseCreatedAt: new Date()    }).then(() => {    (...)};
查看完整描述

1 回答

?
POPMUISE

TA貢獻1765條經驗 獲得超5個贊

沒有針對您要執行的操作的 API。此外,使用隨機集合名稱對數據建模通常不是一個好主意。您的應用程序應該提前知道集合名稱,因為:

  1. 如果您不知道其名稱,則無法查詢集合。

  2. 沒有客戶端 API 可以列出文檔下的子集合。

考慮改為使用名為“courses”的子集合,然后在其下添加一個具有隨機 ID 的文檔。


查看完整回答
反對 回復 2022-12-29
  • 1 回答
  • 0 關注
  • 87 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號