我需要像這樣創建檔案和檔案的子集:

所以這是我的代碼:
function Subscriptions() {
useEffect(() => {
const fetchData = async () => {
try {
const userProjectsColRef = collection(db, "users");
const newProjectDocRef = doc(userProjectsColRef);
addDoc(collection(newProjectDocRef, "experiences"), {
name: "hello",
});
} catch (err) {
console.log(err);
}
};
fetchData();
}, []);
return <div></div>;
}
export default Subscriptions;
如何將資料添加到創建的第一個檔案(帶有“bio”、“fullname”、“company”的“data”欄位)?
現在,這段代碼確實添加了一個名為“experiences”的子集合,其中包含一個包含一些資料的檔案(名稱:“hello”)。像這樣 :

uj5u.com熱心網友回復:
您需要創建兩個檔案:首先是父檔案user,然后
是基于其父檔案(即)的檔案。experienceDocumentReferenceDocumentReferencenewProjectDocRef
const userProjectsColRef = collection(db, "users");
const newProjectDocRef = await addDoc(userProjectsColRef, {
// ...
});
await addDoc(collection(newProjectDocRef, "experiences"), {
// ...
});
請注意,如果您希望將這兩個寫入作為原子操作完成,則應使用批處理寫入。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/466515.html
標籤:javascript 反应 火力基地 谷歌云火库
下一篇:想要過濾一個陣列
