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 => {
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()
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
use doc()
function instead of document()
document()
is a property of functions.firestore
The equivalent for admin.firestore()
is collection().doc()
See Firestore: Get Data
for more info.
admin.firestore().collection('posters').doc(postID) ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With