首页 > 解决方案 > 错误类型错误:路径必须是字符串。在firebase http请求中收到未定义

问题描述

我在 firebase 函数中添加了一个 http 请求,它在本地运行时可以完美运行。

但是部署后会报错:

错误类型错误:路径必须是字符串。收到未定义

这是我用于删除记录的代码:

 exports.deleteoldposts =functions.https.onRequest((request,response)=> 
    {
     var now = Date.now();
     var cutoff = now - 5 * 60 * 1000;
      admin.firestore().collection("topic_database")
     .orderBy('timeInMills')
      .endAt(cutoff)
      .get()
      .then(function(docRef){
        docRef.forEach(docs => {
         console.log(docs.id,docs.data().userId);
         var postId=docs.id;
         var posterId = docs.data().userId;
         docs.ref.delete()
      })
      response.status(200).json("Deleted Succesfully");

      return 0;
    })
    .catch(function(error){
      console.log("error "+error);
      response.status(400).json(error);
    });
     });

任何帮助,将不胜感激。

标签: google-cloud-functions

解决方案


我有同样的问题,我已经通过将 firebase-admin 更新到最新版本来解决

npm install firebase-admin@latest

(我没有足够的声誉,这就是为什么我无法发表评论)


推荐阅读