我想從我的 firestore 收藏中洗掉一個游戲,但出現錯誤:
型別錯誤:doc 不是函式
我正在使用最新版本的 Firebase。洗掉檔案的正確方法是什么?
import {where,query,deleteDoc,collection, doc, getDocs, getFirestore } from "firebase/firestore";
deleteGame(game) {
const db = getFirestore();
const q = query(collection(db, "history"), where("date", "==", game.date));
const doc = getDocs(q);
const quer = await getDocs(q);
quer.forEach((doc) =>
{
deleteDoc(doc(db, "history", doc.id));
});
}
uj5u.com熱心網友回復:
根據洗掉資料的firebase檔案,您確實應該使用
deleteDoc(doc(db, "history", doc.id));
但是 doc 需要是從firebase/firestore. 您正在使用 quer ( quer.forEach(( doc ) => ) 中的元素重寫 doc 的值。
您還const doc = getDocs(q);需要更改兩個doc變數的名稱,以便在 forEach 回呼中使用匯入的函式。
另請記住,這不會是子集合(如果您有任何 - 如檔案中所述)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/322647.html
標籤:javascript 火力基地 谷歌云firestore
上一篇:基于時間戳的云函式查詢監聽器
