.where() firestore query not working properly?

人走茶凉 提交于 2021-01-24 13:39:31

问题


In the below code, when I remove the .where() from my query the query works and I get my comments returned. However, when I use the where query to try and find a comment bound to a post (scream) id, i get a blank array. Am I using .where() incorrectly? Any help would be appreciated.

  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 document model

{
screamId: “id of post commenting on”,
body: “content of comment”,
userHandle: “username of comment”
}

来源:https://stackoverflow.com/questions/56994387/where-firestore-query-not-working-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!