首页 > 解决方案 > 无法读取节点中具有云功能的属性?

问题描述

我有一个云 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;
    
    });

在此处输入图像描述

标签: javascriptnode.js

解决方案


推荐阅读