大家好,我有這樣的結構:
users {
user {
uid: "",
apps: [
{
id: "",
name: "",
points: 0,
},
{
id: "",
name: "",
points: 0,
},
]
}
}
我想更新例如 firestore v9 中的應用程式 [0] 陣列中的點我如何執行此操作我嘗試了點符號之類的方法,但它洗掉了所有其他欄位
const db = getFirestore();
const ref = doc(db, 'users', uid);
const matches = await getDoc(ref);
if (!matches.exists()) return;
return updateDoc(ref, {
"apps.0.points": 50
});
另外,我嘗試洗掉舊的并添加更新的,但我認為這不是一個好方法。
uj5u.com熱心網友回復:
const db = getFirestore();
const ref = doc(db, 'users', uid);
const matches = await getDoc(ref);
if (!matches.exists()) return;
const docData = matches.data()
docData.apps[0].points = 50
return updateDoc(ref, {
...docData
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/485367.html
標籤:javascript 反应 火力基地 谷歌云火库
下一篇:從一維陣列在反應引導中動態創建行
