我需要找到通过.where(...)获取的文档的文档标签(名称/ id?)
我在做什么错了?
// updates dev team in the db
function updateDevTeam(devToUpdate, update) { // devToUpdate = id of dev, fieldToUpdate = goal, name, or team_id, update = value
var devToUpdateDocument = fb.db.collection('dev').where('id', '==', devToUpdate) //how do I set this to the document id(/name/path?)
fb.db.collection('dev').doc(devToUpdateDocument).update({ team_id: update })
}
答案 0 :(得分:0)
您似乎正在尝试更新查询产生的所有文档。 Firestore没有像SQL这样的“更新位置”功能。
如果您没有对该文档的引用,则无法更新该文档。要更新所有与查询匹配的文档,您必须:
// Your query object
const query = fb.db.collection('dev').where('id', '==', devToUpdate)
// now actually perform the query to get a QuerySnapshot
query.get().then(qsnapshot => {
// then iterate each document in the result set to update it
qsnapshot.docs.forEach(dsnapshot => {
// get a reference to the document in the DocumentSnapshot
const ref = dsnapshot.ref
// and update it
ref.update(...)
})
})