我的js文件被正确地输入到DOM中,我在firebase.js文件中插入了防火墙。为什么我得到一个
TypeError‘collection(.).doc不是函数’
集合查询是直接从firebase文档站点获取的,我不明白这怎么可能是类型错误。有什么想法吗?
import { app } from "./firebase";
import { getFirestore, doc, collection } from "firebase/firestore";
const db = getFirestore(app);
// get data
const docRef = collection(db, 'posts').doc('ARt1ctrEjweKEd4gmgCr');
await docRef.get();
if (!doc.exists) {
console.log('No such document!');
} else {
console.log('Document data:', doc.data());
}
发布于 2022-08-22 07:28:55
doc()
是模块化SDK中的顶层函数,而不是collection()
上的一个方法。尝试:
import { getFirestore, doc, getDoc } from "firebase/firestore";
// Creating DocumentReference
const docRef = doc(db, 'posts', 'ARt1ctrEjweKEd4gmgCr');
const docSnap = await getDoc(docRef);
if (!doc.exists) {
console.log('No such document!');
} else {
console.log('Document data:', doc.data());
}
同时结帐:Firestore: What's the pattern for adding new data in Web v9?
https://stackoverflow.com/questions/73447541
复制相似问题