【发布时间】:2019-05-18 08:23:49
【问题描述】:
我正在使用来自 link 的下面这个 firesotre 示例。无论我收到 data.name 中数据的错误 Object is possible 'undefined'。我很确定我在文件中有名字。请问如何解决这个问题。
// Listen for updates to any `user` document.
exports.countNameChanges = functions.firestore
.document('users/{userId}')
.onUpdate((change, context) => {
// Retrieve the current and previous value
const data = change.after.data();
const previousData = change.before.data();
// We'll only update if the name has changed.
// This is crucial to prevent infinite loops.
if (data.name == previousData.name) return null;
// Retrieve the current count of name changes
let count = data.name_change_count;
if (!count) {
count = 0;
}
// Then return a promise of a set operation to update the count
return change.after.ref.set({
name_change_count: count + 1
}, {merge: true});
});
【问题讨论】:
标签: typescript google-cloud-firestore tslint