【问题标题】:Cloud Functions - View all properties of data() object?Cloud Functions - 查看 data() 对象的所有属性?
【发布时间】:2018-06-14 16:44:16
【问题描述】:

当在 Cloud Functions 中使用 onWrite 时,我正在寻找一种方法来 console.log data() 对象内的所有属性。做event.after.data() 只会给我[Object object],这不是很有帮助。

exports.createSubscription = functions.firestore.document('Users/{userUID}').onWrite(event => {
    console.log('Token: ' + event.after.data().token);
    console.log('Email: ' + event.after.data().email);
    console.log('All: ' + event.after.data());         //Just returns [Object object]
}

【问题讨论】:

  • 您是否尝试过使用JSON.stringify(event.after.data())

标签: javascript firebase google-cloud-firestore google-cloud-functions


【解决方案1】:

如果您不在日志中使用字符串连接,您的运气会更好。相反,将对象作为单独的参数传递给 console.log(),它应该比从字符串 concat 获得的更好地扩展每个对象:

console.log('All:', event.after.data())

【讨论】:

    【解决方案2】:

    想通了

    const data = event.after.data();
    console.log('data: ' + Object.keys(data));
    

    【讨论】:

    • 你也可以JSON.stringify(data)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 2017-05-12
    相关资源
    最近更新 更多