javascript - Cloud Firestore 触发器不适用于 Cloud 功能
问题描述
我正在尝试使用 Cloud Firestore 触发器调用 Cloud Function。基本上,每当将新文档添加到“评论”时,我的云功能都会完全导出我的子集合“评论”。我的“评论”子集合中有大约 6-7 个文档。我通过控制台部署了功能,部署完成。但是,每当我将新文档添加到“评论”子集合中时,都不会触发此功能。有人可以告诉我可能是什么问题吗?
触发器类型: Cloud Firestore (Beta) 事件类型: providers/cloud.firestore/eventTypes/document.write 文档路径: test_restaurant/{reviews}
编辑: 我希望我的云功能仅将添加到我的 Firestore 的新文档导出到我的 GCP 存储桶。以下是我正在尝试编写的函数:
const functions = require('firebase-functions');
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient();
const bucket = 'gs://ABC/trigger_test'
exports.newFirestoreBackup = functions.firestore
.document('test_restaurant/{Id}/reviews/{Id}')
.onWrite((change, context) => {
const databaseName = client.databasePath(
// process.env.GCLOUD_PROJECT,
"FS-123",
'(default)'
);
return client
.exportDocuments({
name: databaseName,
outputUriPrefix: bucket,
// Leave collectionIds empty to export all collections
// or define a list of collection IDs:
// collectionIds: ['users', 'posts']
collectionIds: ['reviews'],
})
.then(responses => {
const response = responses[0];
console.log(`Operation Name: ${response['name']}`);
return response;
})
.catch(err => {
console.error(err);
});
});
解决方案
您不共享任何代码,但如果您希望“每当[您]向reviews
子集合添加新文档时”触发您的云函数,则应使用以下路径声明它:
exports.createUser = functions.firestore
.document('test_restaurant/{restaurantId}/reviews/{reviewId}')
.onCreate((snap, context) => {...});
您也可以使用具有onWrite()
相同路径的触发器。
推荐阅读
- flutter - Flutter 这个函数的返回类型是 'Future
',但不以 return 语句结尾 - java - 直接在 tomcat 文件夹中创建图像存储(Java)
- javascript - 并发选项在 p-settle 中似乎没有意义
- javascript - Angular 6:尝试在浏览器关闭事件(浏览器的卸载/卸载事件之前)上进行同步调用(删除)
- java - Azure Cosmos 文档数据库的 Java Api (SQL Api)
- javascript - 使用 JavaScript 将 max-height 设置为 calc 不起作用(无法分配给 CSS 属性)
- r - Plotly and Shiny:是否可以将事件数据作为列表对象获取?
- python - 按列表内的值增加第 i 列元素
- user-interface - 尝试为登录屏幕固定背景
- twa - TWA 性能缓慢