在firebase/firestore
的v9中更新文档时,我遇到了一个错误,我一直在遵循官方文档,不确定我做错了什么:
import { initializeApp } from "firebase/app";
import { getFirestore, updateDoc, doc} from 'firebase/firestore';
import firebaseConfig from '../utils/firestore';
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
function updateSeries(docID, name, desc) {
const data = {
name: name,
desc: desc,
lastUpdatedAt: Timestamp.now(),
}
const seriesDocRef = doc(db, "MY_COL", docID)
return new Promise((resolve, reject) => {
updateDoc(seriesDocRef, data).then(() => {
resolve();
}).catch((e) => {
reject(e);
})
})
}
当我调用这个函数时,我得到了这个错误:
errors.ts:94未捕获的FirebaseError:无效的文档引用。文档引用必须有偶数个段,但MY_COL有1个。
如果传递到doc
函数的值未定义或错误,则可能导致此错误。请检查db
和docID
变量是否在中定义
const seriesDocRef = doc(db, "MY_COL", docID)