firebase - Datastore 模式下 Firestore 的事件触发器 - kind 是否会以某种方式转换为集合名称?

标签 firebase go google-cloud-firestore google-cloud-datastore

根据官方文档,很可能设置一个云函数,该函数将在数据存储区发生更改时调用(添加新文档等)。但是,除非我遗漏了什么,否则似乎此功能是为 Firestore 模式定义的。

对于初学者,我创建了一个简单的 Go 函数,旨在将事件对象打印到日志中:

package dblog

import (
    "context"
    "fmt"

    "cloud.google.com/go/functions/metadata"
)

func DbWatch(ctx context.Context, e map[string]interface{}) error {
    meta, err := metadata.FromContext(ctx)
    if err != nil {
        return fmt.Errorf("metadata.FromContext: %v", err)
    }
    fmt.Printf("%#+v\n%#+v", *meta, e)
    return nil
}

我部署了它
gcloud functions deploy dbwatch --entry-point DbWatch --trigger-event providers/cloud.firestore/eventTypes/document.create --trigger-resource "projects/MYPROJECTIDHERE/databases/(default)/documents/trigger/{triggerid}" --runtime go111 --memory 128MB

到目前为止,该功能已经存在,但是如果我创建一个类型为 trigger 的文档- 根本没有调用记录。要么我遗漏了有关数据存储资源规范的某些内容,要么没有实现触发器。

最佳答案

我了解您为 Datastore 模式下的 Firestore 文档创建的 Cloud Function 未按预期触发。

这确实是预期行为,正如公共(public)文档 [1] 的“限制和保证”部分所述,Firestore 的 Cloud Functions 触发器仅在 native 模式下可用。

因此,您只能使用 Cloud Functions 来监控 Firestore native 文档中的更改。要使用此功能,您需要使用 Firestore 在 native 模式下创建一个新项目 [2]。

[1] https://cloud.google.com/functions/docs/calling/cloud-firestore#limitations_and_guarantees

[2] https://cloud.google.com/datastore/docs/firestore-or-datastore#choosing_a_database_mode

关于firebase - Datastore 模式下 Firestore 的事件触发器 - kind 是否会以某种方式转换为集合名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62225041/

相关文章:

firebase - 运行连续的 firestore 查询时虚假的 MaxListenersExceededWarning EventEmitter 内存泄漏

firebase - 在onPressed操作期间未在Flutter登录表单中找到路由

javascript - admin.auth().currentUser;云函数中返回未定义

javascript - Firebase:使用同一按钮通过 GitHub 登录/注册

firebase - 注册 token 不是有效的 FCM 注册 token

java - 如何遍历 Firebase child 的 child 并将他们的 key 添加到列表中?

http - 去 Gin 框架 : Testing query and POST with cURL

go - 如何在 Gin 的上下文中获取匹配的路由?

javascript - 使用 Firebase 数据库触发器 onUpdate

go - 在 golang 中将 []byte 转换为 "virtual"文件对象的简单方法?