我正在使用firebase开发一个web应用程序,并遇到了这个错误。经过几个小时的调试,我仍然无法理解出了什么问题,我会把代码留在这里,让那些能帮我找出我做错了什么的人。任何建议都会很有帮助,谢谢!
代码:
import {
getFirestore,
addDoc,
doc,
updateDoc,
collection,
query,
where,
getDocs,
setDoc,
} from "firebase/firestore";
const app = initializeApp(firebaseConfig);
const firestore = getFirestore(app);
var files = [....]
getDocs(collection(firestore, "property")).then((querySnapshot) => {
querySnapshot.forEach((doc) => {
if (files.includes(decrypt(doc.data().fileno))) {
if (files.includes(decrypt(doc.data().fileno), 6)) {
let owner = "ABC";
const bref = doc(collection(firestore, "property"), doc.id);
updateDoc(bref,{owner:encrypt(owner)}).then(()=>{
console.log("updated")
})
} else {
let owner = "XYZ";
const bref = doc(collection(firestore, "property"), doc.id);
updateDoc(bref,{owner:encrypt(owner)}).then(()=>{
console.log("updated")
})
}
}
});
});发布于 2022-07-08 00:02:10
您的代码中有两个doc定义:
从Firestore中导入的querySnapshot.forEach((doc) => {.
doc函数,这是您在
doc参数。第二个doc隐藏第一个,这就是为什么不能在回调中调用doc函数的原因。
解决方案是给变量一个不同的名称,比如docSnapshot。
https://stackoverflow.com/questions/72904977
复制相似问题