cbd*_*per 2 node.js firebase typescript google-cloud-functions google-cloud-firestore
以下是 Firestore 云功能的可用触发器:
https://firebase.google.com/docs/firestore/extend-with-functions
在创建
functions.firestore
.document('my-collection/{doc-id}')
.onCreate((snap, context) => { /* ... */ });
Run Code Online (Sandbox Code Playgroud)
删除时
functions.firestore
.document('my-collection/{doc-id}')
.onDelete((snap, context) => { /* ... */ });
Run Code Online (Sandbox Code Playgroud)
更新
functions.firestore
.document('my-collection/{doc-id}')
.onUpdate((change, context) => { /* ... */ });
Run Code Online (Sandbox Code Playgroud)
写时
functions.firestore
.document('my-collection/{doc-id}')
.onWrite((change, context) => { /* ... */ });
Run Code Online (Sandbox Code Playgroud)
我正在将我的项目转换为 Typescript。我应该为 paramschange context和使用什么类型snap?
以下是类型:
在创建:
snapshot: FirebaseFirestore.QueryDocumentSnapshot
context: functions.EventContext
Run Code Online (Sandbox Code Playgroud)
删除:
snapshot: FirebaseFirestore.QueryDocumentSnapshot
context: functions.EventContext
Run Code Online (Sandbox Code Playgroud)
更新:
change: functions.Change<FirebaseFirestore.QueryDocumentSnapshot>
context: functions.EventContext
Run Code Online (Sandbox Code Playgroud)
写时:
change: functions.Change<FirebaseFirestore.DocumentSnapshot>
context: functions.EventContext
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 Typescript,您可以像这样导入/使用:
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
...
export const fnSomeCollectionTriggerOnUpdate =
functions.firestore.document('somecollection/{docId}')
.onUpdate(async (change: functions.Change<admin.firestore.QueryDocumentSnapshot>,
context: functions.EventContext) => {
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
361 次 |
| 最近记录: |