如果试图从快照常量中获取新引用,则
我会这样做的
例子
const areaSnapshot = await admin.firestore().doc("areas/greater-boston").get()
const bostonCities = areaSnapshot.data().cities;
const allAreas = await areaSnapshot.ref.parent.doc("new-york").get()
const nyCities= allAreas.data().cities
console.log(bostonCities, nyCities)
更新文档
//to update document
const areaSnapshot = await admin.firestore().doc("areas/greater-boston").get()
const allAreas = areaSnapshot.ref.parent.doc("new-york").update({
capital: {
liberty: true
}
})
await allAreas
.then(() => {
console.log("success")
})
.catch(err => console.log(err))
资料来源:
https://firebase.google.com/docs/firestore/manage-data/add-data