Gcp/Firebase/CloudFunctions/Realtimedatabaseトリガー
提供: 初心者エンジニアの簡易メモ
functionsでrealtimedatabaseのトリガーを作る
公式:https://firebase.google.com/docs/functions/database-events?hl=ja
サンプル
exports.makeUppercase = functions.database.ref('/Rooms/{pushId}/original') .onCreate((snapshot, context) => { // Grab the current value of what was written to the Realtime Database. const original = snapshot.val(); functions.logger.log('Uppercasing', context.params.pushId, original); // const uppercase = original.toUpperCase(); const uppercase = original; // You must return a Promise when performing asynchronous tasks inside a Functions such as // writing to the Firebase Realtime Database. // Setting an "uppercase" sibling in the Realtime Database returns a Promise. return snapshot.ref.parent.child('uppercase').set(uppercase);
"TypeError: Cannot read property 'name' of undefined at RefBuilder.changeConstructor"エラーが出る場合
cd functions npm install firebase-functions@latest vi functions/package.json
firebase-functionsを3.13.1以上にする。
参考:https://github.com/firebase/firebase-functions/issues/447