0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Cloud Firestoreのデータ更新でCloud functionsをトリガする

0
Posted at

目的

  • firestoreのデータ更新をきっかけにcloudfunctionsを実行する
  • ドキュメントパスの設定値がわからず混乱したためメモまでに記録

環境

cloud functions: 1st gen
ランタイム: Python 3.9

手順

Firebase cloud firestore

  • コレクション名
    funcData

  • funcData、をInsertした時に、関数実行を行う

addDoc(collection(db, "funcData"), { id: "zzz", data: "created" }).then(result => {
      console.log(result)
      console.log("====== ドキュメントパスの確認 ======")
      console.log(result.path) //← ドキュメントパス
    })

cloud functions側の設定

  • 関数の作成を行う
  • トリガーのタイプを Cloud Firestoreにする
  • Event Tyeを今回は作成なのでcreateとする
  • ドキュメントパスは、 コレクション名/ドキュメント名 で指定する
     *  しかし、createだと、ドキュメント名は毎回作られるため取れない。そのため、次のようにdocument名は可変値にすることができる funcData/{document}
    スクリーンショット 2023-04-09 11.21.59.png

function側のソースをデプロイする。

以上。funcDataに新規レコードを作成すると関数が実行される

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?