【发布时间】:2021-11-10 22:38:33
【问题描述】:
我正在尝试使用 where 子句从我的谷歌云功能中查找我的 Firestore 数据库中的文档,这是我下面的代码,当我尝试获取带有 ID 的文档时,它可以工作,但是当我尝试使用where 子句没有,我该如何解决?我做错什么了吗
return await firestore.collection(COLLECTION_NAME).where('APIKEY', '==', '<APIKEY_VALUE>').get().then(doc => {
if (!(doc && doc.exists)) {
return res.status(404).send({
error: 'Unable to find the document'
});
}
const data = doc.data();
console.log(data);
if (!data) {
return res.status(404).send({
error: 'Found document is empty'
});
}
return res.status(200).send(data);
}).catch(err => {
console.error(err);
return res.status(404).send({
error: 'Unable to retrieve the document',
err
});
});
这是我的 Firestore 数据库和我要收集的文档的屏幕截图:
【问题讨论】:
-
运行这段代码时有什么问题?如果您希望查询与文档匹配,但事实并非如此,请编辑您的问题以包含您希望返回的文档的屏幕截图。
-
我添加了截图,请告诉我我做错了什么
-
谢谢。运行代码时会发生什么?有错误吗?如果没有,向客户端发送什么响应?
-
您在查询中使用了
firestore.collection(COLLECTION_NAME)还是firestore.collection('accounts')? -
@FrankvanPuffelen 它给了我这个错误 { "error": "Unable to find the document" }
标签: javascript firebase google-cloud-platform google-cloud-firestore