Created
June 19, 2018 12:09
-
-
Save frankkienl/7803e4758eecfa4ec0c5e5ce0babad07 to your computer and use it in GitHub Desktop.
Call Firestore with Firebase Functions triggered by Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Import libraries | |
const functions = require("firebase-functions"); | |
const admin = require("firebase-admin"); | |
//init | |
admin.initializeApp(); | |
const firestore = admin.firestore(); | |
//Create a function that is triggered by Storage | |
//https://firebase.google.com/docs/storage/extend-with-functions#trigger_a_function_on_changes | |
exports.myFunction = functions.storage.object().onFinalize((object) => { | |
//Call firestore | |
//Get a document | |
let promiseDoc = firestore.doc('path/to/doc').get(); | |
//write a document | |
firestore.doc('path/to/doc').set({data: 'mydata'}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment