Rai*_*lil 6 firebase google-cloud-firestore
我正在运行一个由 firebase 实时数据库更改和更新 FireStore 触发的云函数。但是,虽然函数触发,但函数无法访问 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 => {
Run Code Online (Sandbox Code Playgroud)
此时,控制台日志指出TypeError:admin.firestore(...).document is not a function at..我已经尝试过这个答案:尝试过答案但问题仍然存在。这是否与我在 firebase 云功能内部访问 firestore 的事实有关?我的云功能是否没有正确更新?
编辑(包括初始化代码)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
Run Code Online (Sandbox Code Playgroud)
此外,我尝试通过将其更改为来调试该功能:
if (revealedValue === true) {
var updates = {}
const postID = context.params.postIDthatWasRevealed
return admin.firestore()
Run Code Online (Sandbox Code Playgroud)
现在,当我触发该函数时,我得到Function execution took 811 ms, finished with status: 'ok'这样的结果,似乎 firestore 函数是有效的,只是我的语法可能已关闭,或者我可能忘记了某些东西
document() 是一个属性 functions.firestore
等效于admin.firestore()IScollection().doc()
查看Firestore: Get Data更多信息。
admin.firestore().collection('posters').doc(postID) ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4346 次 |
| 最近记录: |