Access db data in Cloud Functions for Firebase

后端 未结 1 2013
梦毁少年i
梦毁少年i 2020-12-03 14:57

In Cloud Functions for Firebase, for example:

exports.makeUppercase = functions.database.ref(\'/messages/{pushId}/original\')
    .onWrite(event => {
           


        
相关标签:
1条回答
  • 2020-12-03 15:29
    const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    admin.initializeApp(functions.config().firebase);
    
    exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
        .onWrite(event => {
         const getSomethingPromise = admin.database().ref(`/important/messages/{pushId}`).once('value');
    
         return getSomethingPromise.then(results => {
            const somethingSnapshot = results[0];
    
            // Do something with the snapshot
        })
    })
    

    Check this example for instance: https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js

    0 讨论(0)
提交回复
热议问题