Trying to follow the instructions on this page and I can't figure out how to simply get to the data in the DocumentSnapshot.
They do not really explain updating onCreate, except to say it is the same as onDelete, and I can't get that to work.
exports.mFoo = functions.firestore
.document('foos/{key}')
.onCreate((snap, context) => {
const bar = snap.data(); // <-- DOESN'T WORK
console.log(bar); // <-- DOESN'T WORK
return Promise;
});
I get the following error:
TypeError: snap.data is not a function at exports.mFoo.functions.firestore.document.onCreate
I'm sure it's super simple but I don't really understand this stuff and I have tried tons of combinations of stuff and nothing works.
Turns out I ran into the same problem that I have before.
Before doing any of these types of updates:
First I have to open my package.json file and delete any dependencies that are going to be updated.
These were what I found there:
After leaving the dependencies empty and rerunning those commands to install, these showed up:
Apparently installs and upgrades won't fix these dependencies but they will add them if they aren't there. Maybe it is possible to fix it by typing those in but I wouldn't have had a clue what version numbers to put there.
Now the (modified) code works:
Thanks @Todd Kerpelman for pointing me in the right direction and @Bob Snyder because the same answer from the other post worked for me here also.