![](/img/trans.png)
[英]Why is querySelector() returning null even though the class does exist?
[英]Why might .exists be returning false in Firestore, even if a document does exist?
我正在尝试检查 Firestore 中是否存在文档 - 如果它已经存在,我想返回以便我不会重复该条目。 我已经按照 此处的说明进行操作,其他答案中也引用了该说明,但是当我逐步执行该程序时,我看到“存在”始终设置为 false。 因此,每次执行此代码时,都会添加一个重复条目。 当条目已经存在时,有什么我可以尝试弄清楚为什么exists没有设置为true的吗?
非常感谢!
var docRef = db.collection('collection-testing').doc(docName);
docRef.get().then((doc) => {
let exists = doc.exists;
if (exists) {
return;
}
});
/* Loads new entry below*/
我找到了问题所在。 我的文档仅用于存储集合,但没有为文档本身设置任何数据。 在.set()
添加数据后,上面的代码现在按预期运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.