错误:索引为0的元素不是有效的DocumentReference

时间:2019-10-31 10:06:20

标签: firebase google-cloud-firestore google-cloud-functions

我想检索用户订阅/关注的所有博客(如Instagram)。我正在使用Firebase Cloud Functions和Firestore。

exports.currentUserSubscriberPost = (req, res) => {
  const subscriberDoc = db
    .collection("subscriber")
    .where("userHandle", "==", req.user.handle);
  let subscribing = [];
  const BlogsDoc = db.collection("blogs");
  subscriberDoc
    .get()
    .then(async doc => {
      doc.forEach(data => {
        subscribing.push({ subscribingUserId: data.data().userId });
      });
      if (subscribing.length > 0) {
        let ref = subscribing.map((user) => db.collection('blogs').where('userId','==',user.subscribingUserId));

        let blogsData = await db.getAll(...ref);
        return blogsData;
      } else {
        return res.json({ msg: "you are not subscribing to anyOne" });
      }
    })
    .then(data => {
      let blogs = [];
      data.forEach(data => {
        blogs.push( data.data() );
      });
      return res.json(blogs);
    }).catch(err => console.error(err))
};


1 个答案:

答案 0 :(得分:0)

您需要使用queryParameters方法解析要获取的查询对象。您应该遍历查询和get来调用where

所需的实际DocumentReference对象。