javascript - 无法读取节点中具有云功能的属性?
问题描述
我有一个云 Firebase 功能,当将文档添加到集合中时,它会从 Firestore 触发。我在解析 json 时遇到问题。
TypeError: Cannot read property 'venue' of undefined
at exports.updateCollectionCount.functions.firestore.document.onWrite (/workspace/index.js:136:24)
我真的不熟悉 JS,所以我认为我的语法可能是错误的,或者可能遗漏了一些async
keyword
,因为有时解析工作正常。我正在寻找场地地图中的 id 值。
exports.updateCollectionCount = functions.firestore
.document('orders/{order}')
.onWrite((change, context) => {
let map = change.after.data();
console.log(map);
let venue = map['venue']; /// here is where my error is (line 36)
console.log(venue);
const venueId = venue['id'];
let orderType = map['orderType'];
if(orderType === 'Collection'){
db.collection('venues').doc(`${venueId}`).update({"collectionCount":admin.firestore.FieldValue.increment(1)})
}
return;
});
解决方案
推荐阅读
- python - 由于未在所有 CPU 内核中充分利用,Python Pandas 合并大型数据集的速度很慢,用于在两个数据帧中查找共同元素
- mysql - 在字符串中查找子字符串,如果确实存在,则将其插入另一个表 SQL
- sql - Oracle PL/SQL - 在插入“表不存在”之前出错?
- sql - SQL 搜索最佳匹配
- c++ - 2串LCM
- node.js - Heroku 错误 H12 和 H28 Node.js
- scala - 计算特定列 ID Scala 的日期差异
- left-join - clickhouse : 使用 IN 左连接
- php - Add_filter 将新列添加到 Woocommerce 产品属性表(属性添加/编辑页面)
- flutter - 如何在 Flutter 中的对话框关闭时重定向到特定路由