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

Event triggers for Firestore in Datastore mode - does kind translates into the collection name somehow?

根据官方文档,很有可能设置一个云函数,该函数将在数据存储区发生变化时调用(添加新文档等)。但是看起来这个功能是为 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]的 "Limitations and guarantees" 部分所述,Firestore 的 Cloud Functions 触发器仅在本机模式下可用。

因此,您只能使用 Cloud Functions 来监控 Firestore 本机文档中的更改。要使用此功能,您需要在本机模式下使用 Firestore 创建一个新项目[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