我在 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);
});
});
如有任何帮助,我们将不胜感激。
最佳答案
我有同样的问题,我已通过将 firebase-admin 更新到最新版本来解决
npm install firebase-admin@latest
(我没有足够的声誉,这就是为什么我无法发表评论)
关于google-cloud-functions - 错误 TypeError : Path must be a string. 在 firebase http 请求中收到未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54108659/