【发布时间】:2020-04-29 06:01:14
【问题描述】:
我正在尝试在 Cloud Firestore 中设置一个函数,该函数将在将新文档添加到特定集合时触发。我希望使用 TypeScript 来做到这一点,因为有人告诉我在编写异步代码时它更容易使用。以下 JavaScript 代码按预期工作,并在我在指定位置添加新文档时触发:
//This JavaScript code works
import * as functions from 'firebase-functions';
exports.waitReportCreatedJS = functions.firestore
.document('merchant_locations/{merchantId}/wait_period/{waitId}')
.onCreate((snapshot, context) => {
console.log('WaitReportCreated has been triggered');
const merchantId = context.params.merchantId
const waitId = context.params.waitId
console.log(`New wait recorded: ${waitId} at ${merchantId}`);
return snapshot.ref.update({ waitId: waitId })
});
但是当我尝试使用 TypeScript 做同样的事情时,它无法触发 - 当我添加文档时什么都没有发生:
//But this TypeScript code doesn't seem to even trigger
import * as functions from 'firebase-functions';
export const waitReportCreatedTS = functions.database
.ref('merchant_locations/{merchantId}/wait_period/{waitId}')
.onCreate((snapshot, context) => {
console.log('WaitReportCreated has been triggered');
const merchantId = context.params.merchantId
const waitId = context.params.waitId
console.log(`New wait recorded: ${waitId} at ${merchantId}`);
return snapshot.ref.update({ waitId: waitId })
})
我对 Firestore 功能非常陌生,完全不知道我做错了什么。感谢您能给我的任何帮助。
【问题讨论】:
-
functions.firestore != functions.database。不同的数据库产品。
标签: javascript typescript firebase google-cloud-firestore