我们是一个没有模式的模型,在将文档添加到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}
等等..。
发布于 2020-02-26 16:13:26
云函数触发器不允许跨多个集合名称或文档ID的通配符。如果需要在任意数量的路径上触发函数,则需要分别定义它们,但每个函数可以共享一个公共实现,如下所示:
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
}发布于 2020-11-27 14:33:01
使用防火墙函数,您可以使用通配符路径来触发每个可能的路径。但是,您需要为每个文档级别(即- depth=1、depth=2、depth=3等)指定一个触发器。下面是我写来处理4层以下内容的文章:
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);
});
发布于 2022-08-02 09:24:40
为了解决这个错误,我查看了firebase-debug.log中的日志,并看到了以下错误:
"description": "Expected value chat/{tenant}/{customerId} to match regular expression [^/]+/[^/]+(/[^/]+/[^/]+)*"
如果你看正则表达式,它要求的是偶数的路径。我更新了路径,它起了作用。
https://stackoverflow.com/questions/60411815
复制相似问题