Reputation: 71
I'm having difficulty accessing a Firestore document within a Google Cloud Functions function.
I've tried many different admin.initializeApp configurations. I've tried using my service account, I've tried using different collection().doc() code. I've tried different Promise constructions (returning a Promise, .then, callbacks). I'm not including the Cloud Functions call, because that part is working fine. Below is the important code:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp()
var db = admin.firestore();
const setRenderNodeStatus = (instanceName) => {
console.log("settingRenderNodeStatus")
db.collection('renderNodes').doc('i8IFQbR5gHBw0zhdcNyY').get().then((doc) => {
console.log(doc.data())})
.catch((err) => console.log(err))
}
exports.WriteAfterEffectsRenderFile = functions.firestore.document('renders/{renderId}').onCreate((change, context) => {
setRenderNodeStatus("vrzn-test-001")
})
Just looking to get the doc's data. It generally dies and the function doesn't run. If I comment out the call, then the first log line prints out.
Upvotes: 0
Views: 58
Reputation: 317372
You haven't declared a function using the firebase-functions
SDK. All you've done here is declare an arbitrary function. It's not clear how you expect to invoke it, or under what circumstances. It's not possible to declare random functions to run at deployment - you need to use the SDK to declare the circumstances of execution. Please review the documentation and follow one of the examples.
Upvotes: 2