在下面的代码中,当我从查询中删除.where()时,查询有效,并且返回了我的注释。但是,当我使用where查询尝试查找绑定到帖子(尖叫)ID的评论时,我得到一个空白数组。我在错误地使用.where()吗?任何帮助将不胜感激。
exports.getScream = (req, res) => {
let screamData = {};
db.doc(`/screams/${req.params.screamId}`)
.get()
.then((doc) => {
screamData = doc.data();
screamData.screamId = doc.id;
return db
.collection('comments')
.where('screamId', '==', screamData.screamId) //query that doesnt seem to be working
.orderBy('createdAt', 'desc')
.get();
})
.then((data) => {
screamData.comments = [];
data.forEach((doc) => {
screamData.comments.push(doc.data());
});
return res.json(screamData);
})
.catch((err) => {
console.error(err);
res.status(500).json({ error: err.code });
});
}
Firestore文档模型
{
screamId: “id of post commenting on”,
body: “content of comment”,
userHandle: “username of comment”
}