admin管理员组文章数量:1399499
I want to create only one function to be triggered by some of my Collections
, it looks like it's possible with the use of CEL
braced expression or REGEX
, however I failed to figure out the correct form to properly trigger the function.
For example if I have 6 collections "Col1
through Col6
", how can modify this function to be triggered by Col3
and Col5
only
export const writeTrigger = onDocumentWritten({document:"{collectionName}/{docId}"}, triggerFunctionHandler)
Reference Firebase Functions Type Definition
Edit
Line 183 of This Document
/**
* Event handler that triggers when a document is created, updated, or deleted in Firestore.
*
* @param documentOrOpts - Options or a string document path.
* @param handler - Event handler which is run every time a Firestore create, update, or delete occurs.
*/
export function onDocumentWritten<Document extends string>(
documentOrOpts: Document | DocumentOptions<Document>,
handler: (
event: FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>
) => any | Promise<any>
): CloudFunction<FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>> {
return onChangedOperation(writtenEventType, documentOrOpts, handler);
}
Line 147
/** DocumentOptions extend EventHandlerOptions with provided document and optional database and namespace. */
export interface DocumentOptions<Document extends string = string> extends EventHandlerOptions {
/** The document path */
document: Document | Expression<string>;
/** The Firestore database */
database?: string | Expression<string>;
/** The Firestore namespace */
namespace?: string | Expression<string>;
}
which points to Firebase Functions Type Definitions line 25
/*
* A CEL expression which can be evaluated during function deployment, and
* resolved to a value of the generic type parameter: i.e, you can pass
* an Expression<number> as the value of an option that normally accepts numbers.
*/
export abstract class Expression<T extends string | number | boolean | string[]>
And it looks to me that this can use CEL to trigger selective collections, and I may be very much reading this wrong.
I want to create only one function to be triggered by some of my Collections
, it looks like it's possible with the use of CEL
braced expression or REGEX
, however I failed to figure out the correct form to properly trigger the function.
For example if I have 6 collections "Col1
through Col6
", how can modify this function to be triggered by Col3
and Col5
only
export const writeTrigger = onDocumentWritten({document:"{collectionName}/{docId}"}, triggerFunctionHandler)
Reference Firebase Functions Type Definition
Edit
Line 183 of This Document
/**
* Event handler that triggers when a document is created, updated, or deleted in Firestore.
*
* @param documentOrOpts - Options or a string document path.
* @param handler - Event handler which is run every time a Firestore create, update, or delete occurs.
*/
export function onDocumentWritten<Document extends string>(
documentOrOpts: Document | DocumentOptions<Document>,
handler: (
event: FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>
) => any | Promise<any>
): CloudFunction<FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>> {
return onChangedOperation(writtenEventType, documentOrOpts, handler);
}
Line 147
/** DocumentOptions extend EventHandlerOptions with provided document and optional database and namespace. */
export interface DocumentOptions<Document extends string = string> extends EventHandlerOptions {
/** The document path */
document: Document | Expression<string>;
/** The Firestore database */
database?: string | Expression<string>;
/** The Firestore namespace */
namespace?: string | Expression<string>;
}
which points to Firebase Functions Type Definitions line 25
/*
* A CEL expression which can be evaluated during function deployment, and
* resolved to a value of the generic type parameter: i.e, you can pass
* an Expression<number> as the value of an option that normally accepts numbers.
*/
export abstract class Expression<T extends string | number | boolean | string[]>
And it looks to me that this can use CEL to trigger selective collections, and I may be very much reading this wrong.
Share Improve this question edited Mar 26 at 18:08 Wisam Jbori asked Mar 26 at 7:54 Wisam JboriWisam Jbori 1131 silver badge8 bronze badges 2 |1 Answer
Reset to default 1The wildcards used in functions definitions don't accept CEL expressions or regular expressions. All you can do is use a named wildcard on the entire part of a document path (collection or document) using a placeholder in curly braces. The code you're citing isn't relevant to the matching of these named wildcard paths.
The limitation on these wildcards isn't part of the Firebase CLI at all - it's a limitation in Google Cloud Platform internally. You're bound to this limitation even if you're using GCP Firestore functions directly (read the part of that doc that discusses wildcards and paramters) and not using the Firebase tools that wrap them.
If you want a function to trigger on only two specifically named collections, you will need to declare two different triggers, each using that name coded into the path string. They can both call into the same JS implementation function if you want, but you can't avoid declaring and exporting the triggers separately.
See also:
Cloud function trigger for multiple collections which start with a same text
Cloud Functions for Firebase "Create" Trigger - multiple collections
本文标签: google cloud firestoreHow to use Expression in Firebase Trigger FunctionsStack Overflow
版权声明:本文标题:google cloud firestore - How to use Expression in Firebase Trigger Functions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744159626a2593275.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Col1
throughCol6
), and you need to trigger a function each time a new document withinCol3
andCol5
is written, right? – Alex Mamo Commented Mar 26 at 8:57