admin.firestore(...).document在导出时不起作用 [英] admin.firestore(...).document is not a function at exports
问题描述
我正在运行由Firebase实时数据库更改触发的云功能并更新FireStore.但是,尽管该函数触发了,但该函数无法访问Firestore.
I am running a cloud function that is triggered by a firebase realtime database change and updates FireStore. However, although the function triggers, the function cannot access the Firestore.
exports.reveal = functions.database.ref('/reveals/{postIDthatWasRevealed}/revealed').onUpdate((change, context) => {
const revealedValue = change.after.val()
if (revealedValue === true) {
var updates = {}
const postID = context.params.postIDthatWasRevealed
return admin.firestore().document('/posters/' + postID).get().then(querySnapshot => {
这时,控制台日志指出 TypeError:admin.firestore(...).document不是函数.
我已经尝试过此答案:尝试答案,但问题仍然存在.这是否与我正在访问Firebase云功能内部的firestore有关?我的云功能是否没有正确更新?
At this point, the console log states TypeError:admin.firestore(...).document is not a function at..
I have already tried this answer :Tried Answer But the problem continues. Does this have to do with the fact that I am accessing firestore inside of firebase cloud function? Are my cloud functions not properly updated?
编辑(包括初始化代码)
Edit (Includes Initialization code)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
此外,我尝试通过将功能更改为来调试该功能:
In addition, I have tried to debug the function by changing it to :
if (revealedValue === true) {
var updates = {}
const postID = context.params.postIDthatWasRevealed
return admin.firestore()
现在,当我触发函数时,我得到函数执行耗时811 ms,状态为:"ok"
因此,似乎firestore函数是有效的,只是我的语法可能离开,或者我可能会忘记一些东西
Now, when I trigger the function, I get Function execution took 811 ms, finished with status: 'ok'
Thus, it seems as if the firestore function is valid, just that my syntax may be off or I may be forgetting something
推荐答案
使用 doc()
函数代替 document()
这篇关于admin.firestore(...).document在导出时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!