【发布时间】:2020-06-26 03:28:00
【问题描述】:
我正在我的 firestore 数据库中查询工作区 ID。但是,snapshot.empty 评估为 true,即使我可以在我的 firestore 仪表板中看到具有正确 ID 的文档。我是否错误地查询数据库?结果是console.log("No matching documents")
TIA
async function my_func(workspaceID) {
console.log(workspaceID);
db.collection('workspaces')
.where('team_id', '==', workspaceID)
.get()
.then((snapshot) => {
console.log(snapshot);
if (snapshot.empty) {
console.log('No matching documents.');
return;
}
})
.catch((err) => console.log("Error fetching doc for wsID, ", err))
};
编辑
本例中team_id的值为“T015KLJHGV9”,是一个字符串。 workspaceID 的值,当我用typeof workspaceID 检查它时也是一个字符串
【问题讨论】:
-
Firestore 的查询相等条件是类型敏感的,所以试试这个
.where('team_id', '==', parseInt(workspaceID, 10)) -
请编辑问题以显示您尝试查询的数据。如果我们看不到您的查询实际上与您的数据匹配,我们无能为力。我们需要知道您正在使用的 workspaceID 的值,以及应该匹配的特定文档。
标签: javascript firebase google-cloud-firestore