![](/img/trans.png)
[英]How do you find a document by its ID using version 9 of the Firebase JS SDK?
[英]Firebase - Needing to find document id using 'where'
我需要找到我使用 .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 })
}
看起來您正在嘗試更新由查詢產生的所有文檔。 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(...)
})
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.