首页 > 解决方案 > 触发器中使用通配符时部署云函数失败

问题描述

我正在尝试部署一个云功能,该功能将在将文档添加到特定集合时触发,如下所示:

const admin = require("firebase-admin");
const functions = require("firebase-functions");

const Firestore = require("@google-cloud/firestore");
const firestore = new Firestore({ projectId: config.projectId });

admin.initializeApp(config);

exports.checkCapacity = functions.firestore.document("gran_canaria/las_palmas_1/miller_pendientes/{albnum}")
  .onCreate(async (snapshot, context) => {});

但是,这会引发部署失败错误:

未能配置触发器提供程序/cloud.firestore/eventTypes/document.create@firestore.googleapis.com ( gcf .us-central1.checkCapacity)

如果我删除通配符并将引用更改为:

"gran_canaria/las_palmas_1/miller_pendientes/albnum"

我尝试将方法更改为 onWrite(),删除并重新部署该函数并在https://status.cloud.google.com/检查云状态,但找不到任何解决方案。

标签: javascriptnode.jsgoogle-cloud-firestoregoogle-cloud-functions

解决方案


我已经能够在我的 Cloud Firestore 上成功部署一个带有 onCreate 事件触发器的 Cloud Function。

在使用以下内容创建云时,我通过暗示在控制台 UI 中使用提供的模板取得了成功:

在此处输入图像描述

使用的 index.js 是 GCP 在创建函数时提供的示例,它只是打印到日志中哪个文档触发了更改。

查看 Firestore 中的文档,我发现您可能使用了那里提供的示例,因此使用上述设置可能会使其适合您。


推荐阅读