【发布时间】:2020-10-15 16:13:56
【问题描述】:
我正在尝试使用 Cloud Firestore 触发器调用 Cloud Function。基本上,每当将新文档添加到“评论”时,我的云功能都会完全导出我的子集合“评论”。我的“评论”子集合中有大约 6-7 个文档。我通过控制台部署了功能,部署完成。但是,每当我将新文档添加到“评论”子集合中时,都不会触发此功能。谁能告诉我可能是什么问题?
触发器类型: Cloud Firestore(测试版) 事件类型: 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);
});
});
【问题讨论】:
-
你能分享一下你的云函数的整个代码吗?
-
用我的云函数代码@Renaud Tarnec 编辑了问题
标签: javascript node.js firebase google-cloud-firestore google-cloud-functions