【发布时间】:2021-07-10 16:24:47
【问题描述】:
我正在使用 TypeScript 编写 Firebase 可以函数,以下是更新文档的简单方法。
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp(functions.config().firebase);
export const handleTestData = functions.firestore.document('test/{docID}').onCreate(async (snap, context) => {
const data = snap.data();
if (data) {
try {
await admin.firestore().doc('test1/' + context.params.docID + '/').update({duplicate : true});
} catch (error) {}
}
});
在此方法中,promise 由async await 处理,并且没有return 语句,它工作正常。我见过的大多数示例/教程在每种方法中总是有一个return 语句。
我在 Firebase Cloud Functions 中没有返回任何内容是否有任何影响/差异?如果我应该返回一些东西,我可以返回null吗?
【问题讨论】:
标签: firebase google-cloud-firestore promise google-cloud-functions