Javascript 云Firestore触发器不适用于云函数
我正在尝试使用Cloud Firestore触发器调用云函数。基本上,我的云功能是在“评论”中添加新文档时,将我的子集合“评论”完全导出。我的“评论”子收藏中有大约6-7个文档。我通过控制台部署了该功能,部署完成。但是,每当我向“审阅”子集合添加新文档时,不会触发此功能。有人能告诉我可能是什么问题吗 触发器类型:云Firestore(测试版) 事件类型:提供者/cloud.firestore/eventTypes/document.write 文档路径:test_restaurant/{reviews} 编辑: 我希望我的云功能只将添加到firestore的新文档导出到我的GCP存储桶中。下面是我试图编写的函数:Javascript 云Firestore触发器不适用于云函数,javascript,node.js,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Firestore,Google Cloud Functions,我正在尝试使用Cloud Firestore触发器调用云函数。基本上,我的云功能是在“评论”中添加新文档时,将我的子集合“评论”完全导出。我的“评论”子收藏中有大约6-7个文档。我通过控制台部署了该功能,部署完成。但是,每当我向“审阅”子集合添加新文档时,不会触发此功能。有人能告诉我可能是什么问题吗 触发器类型:云Firestore(测试版) 事件类型:提供者/cloud.firestore/eventTypes/document.write 文档路径:test_restaurant/{revi
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);
});
});
控制台代码段:
您不共享任何代码,但如果您希望“每当[您]向
审阅
子集合添加新文档时”触发云功能,则应使用以下路径声明:
exports.createUser = functions.firestore
.document('test_restaurant/{restaurantId}/reviews/{reviewId}')
.onCreate((snap, context) => {...});
您也可以使用相同路径的触发器。您能分享您的云函数的全部代码吗?用我的云函数代码@Renaud tarnec编辑了这个问题即使我通过控制台创建云函数,我是否也必须将上述代码包含在我的index.js中?我已经在控制台中指定了触发器和文档路径,所以我需要在我的云函数中再次提到这一点吗?(我也附上了控制台代码段)