I'm trying to get some information from the update of a firestore file through functions.
I've already managed to get the firestore trigger right (functions is working when my firestore file is updated), but I cannot get the information that was updated through functions.
Here is my functions code:
import * as functions from "firebase-functions";
//const functions = require('firebase-functions');
const admin = require("firebase-admin");
admin.initializeApp();
exports.enviaMensagem = functions.firestore
.document("Events/{eventID}/Listas/Convidados")
.onWrite(async (change, context) => {
const eventID = context.params.eventID;
console.log("eventID: ", eventID);
if (change.after.data()) {
const data = change.after.data();
if ( data!.reference) {
console.log(data!.reference);
} else {
console.log('not possible to get the user reference');
}
console.log(data!.toString());
console.log(change.after.toString());
}
});
[SOLVED] My problem number 1 is when I try console.log(data!.toString());
the return to the console becames [object Object]
and not the actual data.
[SOLVED] My problem number 2 is that I cannot get the info that has been inserted to the firestore file.
this is the structure of the info that has been inserted to the firestore file: updated data structure
the structure is: {[reference key]:{apelido:'abc', estado:'def', referencia:[reference key]}}
I need to retrive the reference key, which is the primary tag for this map, and also inside the structure by the tag "referencia"
How can I retrive this reference key so I can use it?
Thanks for your help!
UPDATE Here is the print of my logged object: Logged object I need to retrive this long string that appears on top and botton of the log "bJaETeYN4hYJqRN9PnmWfrhs7eC2" This string is different for every user and I need the info of which user is doing the action.
UPDATE 2
I've managed to get what I need with the function Object.keys(data!)[0]
I'm leaving the solution here so other can use it!