facebook twitter hatena line email

「Gcp/Firebase/CloudFunctions/Realtimedatabaseトリガー」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(functionsでrealtimedatabaseのトリガーを作る)
(functionsでrealtimedatabaseのトリガーを作る)
行16: 行16:
 
       return snapshot.ref.parent.child('uppercase').set(uppercase);
 
       return snapshot.ref.parent.child('uppercase').set(uppercase);
 
</pre>
 
</pre>
 +
 +
件数取得サンプル
 +
https://www.sukerou.com/2019/07/firebase-database.html
 +
 
==="TypeError: Cannot read property 'name' of undefined at RefBuilder.changeConstructor"エラーが出る場合===
 
==="TypeError: Cannot read property 'name' of undefined at RefBuilder.changeConstructor"エラーが出る場合===
 
  cd functions
 
  cd functions

2021年10月8日 (金) 05:06時点における版

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);

件数取得サンプル https://www.sukerou.com/2019/07/firebase-database.html

"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