問題很簡單。我想創建一個包含集合的檔案。另一種措辭是我需要在檔案中創建一個集合。
我需要能夠在 React 中做到這一點。
視覺:集合 -> 檔案 -> 集合
這里是我需要添加代碼的地方:
const addUser = async () => {
await addDoc(usersCollectionRef, {
name: newName,
grade: Number(newGrade),
role: newRole,
hours: Number(newHours),
//Collection Creation should go here as this is where I am making the new document.
})
}
注意:這是反應而不是本機反應
uj5u.com熱心網友回復:
如果我理解正確,您想在您剛剛在上面的代碼中創建的檔案中創建一個新集合。集合不能為空,因此您必須將一些資料放入集合中的檔案中。可以做到這一點的一種方法是這樣的:
const usersCollectionRef = colleciton(db, 'users')
const addUser = async () => {
const document = await addDoc(usersCollectionRef, {
name: newName,
grade: Number(newGrade),
role: newRole,
hours: Number(newHours),
})
const newCollectionRef = collection(db, 'users', document.id, 'name of new subcollection')
await addDoc(newCollectionRef, {
data: 'Hello World!',
})
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/437915.html
標籤:javascript 火力基地 谷歌云火库
