I can quite easily find how to add triggers for firestore events but I can't find any documentation on how to use firebase functions to write to firestore.
For example I have the following:
export const listener = functions.auth.user().onCreate((x)=>{
//firestore function to add an entry for user with fields...
})
There doesn't seem to be a way to do this? Is it that the logic for adding data to firestore should be written client side? If so wouldn't that mean I would need to re-write that functionality for every platform?
Cloud Firestore function triggersfirestore object that allows you to create handlers tied to specific Cloud Firestore events. Event Type. Trigger. onCreate. Triggered when a document is written to for the first time.
You can use the Firebase Admin SDK to read and write Firestore in the same way you'd use it to read and write Realtime Database. There are plenty of official examples, especially this quickstart.
const admin = require('firebase-admin');
admin.initializeApp();
admin.firestore().collection('messages').add({original: original}).then(writeResult => {
// write is complete here
});
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