How to run query from inside of Cloud function?

前端 未结 1 1186
你的背包
你的背包 2020-12-01 21:42

I\'d like to perform a query on my database once a cloud function on my Firebase app is called.

Let\'s say I have a certain trigger on the database, consider the exa

1条回答
  •  臣服心动
    2020-12-01 22:25

    You can use the Node.js Admin SDK for this:

    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 => {
        return admin.database().ref('/other')
          .orderByChild('id').equalTo(event.params.pushId)
          .once('value').then(snapshot => {
            // there, I queried!
          });
      });
    

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