首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带通配符路径的修复云函数触发器

带通配符路径的修复云函数触发器
EN

Stack Overflow用户
提问于 2020-02-26 10:31:04
回答 3查看 1.1K关注 0票数 5

我们是一个没有模式的模型,在将文档添加到defects集合时,我希望触发一个云函数。问题是,任何defect都可以包含一组新的缺陷集合(递归)。

如何在以下任何文档上设置触发更新/创建的云功能:

problem/defects/{document}

problem/defects/{document}/defects/{document}

problem/defects/{document}/defects/{document}/defects/{document}

problem/defects/{document}/defects/{document}/defects/{document}/defects/{document}

等等..。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-02-26 16:13:26

云函数触发器不允许跨多个集合名称或文档ID的通配符。如果需要在任意数量的路径上触发函数,则需要分别定义它们,但每个函数可以共享一个公共实现,如下所示:

代码语言:javascript
复制
functions.firestore.document("coll1/doc").onCreate(snapshot => {
    return common(snapshot)
})

functions.firestore.document("coll2/doc").onCreate(snapshot => {
    return common(snapshot)
})

function common(snapshot) {
    // figure out what to do with the snapshot here
}
票数 2
EN

Stack Overflow用户

发布于 2020-11-27 14:33:01

使用防火墙函数,您可以使用通配符路径来触发每个可能的路径。但是,您需要为每个文档级别(即- depth=1、depth=2、depth=3等)指定一个触发器。下面是我写来处理4层以下内容的文章:

代码语言:javascript
复制
const rootPath = '{collectionId}/{documentId}';
const child1Path = '{child1CollectionId}/{child1DocumentId}';
const child2Path = '{child2CollectionId}/{child2DocumentId}';
const child3Path = '{child3CollectionId}/{child3DocumentId}';

export const onCreateAuditRoot = functions.firestore
  .document(`${rootPath}`)
  .onCreate(async (snapshot, context) => {
    return await updateCreatedAt(snapshot);
  });

export const onCreateAuditChild1 = functions.firestore
  .document(`${rootPath}/${child1Path}`)
  .onCreate(async (snapshot, context) => {
    return await updateCreatedAt(snapshot);
  });

export const onCreateAuditChild2 = functions.firestore
  .document(`${rootPath}/${child1Path}/${child2Path}`)
  .onCreate(async (snapshot, context) => {
    return await updateCreatedAt(snapshot);
  });

export const onCreateAuditChild3 = functions.firestore
  .document(`${rootPath}/${child1Path}/${child2Path}/${child3Path}`)
  .onCreate(async (snapshot, context) => {
    return await updateCreatedAt(snapshot);
  });

票数 3
EN

Stack Overflow用户

发布于 2022-08-02 09:24:40

为了解决这个错误,我查看了firebase-debug.log中的日志,并看到了以下错误:

"description": "Expected value chat/{tenant}/{customerId} to match regular expression [^/]+/[^/]+(/[^/]+/[^/]+)*"

如果你看正则表达式,它要求的是偶数的路径。我更新了路径,它起了作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60411815

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档