I am following the code in this wiki page: https://firebase.google.com/docs/functions/firestore-events and have deployed the following code to a cloud function:
const { initializeApp } = require('firebase-admin/app');
const { getFirestore } = require('firebase-admin/firestore');
const uuid = require('uuid');
const functions = require('firebase-functions');
initializeApp()
const db = getFirestore();
exports.newDoc = functions.firestore
.document('doc/{docId}')
.onCreate((snap, context) => {
console.log(context.params.docId);
console.log(snap.data());
db.collection('monitor').doc(uuid.v1()).set(snap.data()).then(_=>console.log('saved'));
});
When I add a doc to my 'doc' collection via the Firestore console it adds a document to my 'monitor' collection. When I check for the 'context.params.docId' log however there is a line there but it is completely empty (no contents at all). What am I missing?
I managed to find my id by logging the entire context :) It is actually in the params object but as context.params.pushId