错误:函数执行失败。详细信息:无法读取未定义的属性“ Inload_ID”

时间:2019-01-22 13:07:40

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

我希望获得一些帮助,以了解这段代码的错误之处。我收到此错误。 “错误:函数执行失败。详细信息: 无法读取未定义的属性“ Inload_ID”

我以此为模板。 https://blog.questionable.services/article/from-firestore-to-bigquery-firebase-functions/

我的问题是Google Cloud Functions代码已从原始帖子更新。现在我被困住了。

    const functions = require("firebase-functions")
    const {BigQuery} = require('@google-cloud/bigquery')

   exports.permitsToBQ = functions.firestore
  .document("/inload/{inloadID}")
  .onCreate((snap, context) => {
  const newValue = snap.data();

    // Set via: firebase functions:config:set cls.{dataset,table}
    let config = functions.config()
    let datasetName = config.cls.dataset || "cls"
    let tableName = config.cls.table || "permits"
    let bigquery = new BigQuery()

    let dataset = bigquery.dataset(datasetName)
    dataset.exists().catch(err => {
      console.error(
        `dataset.exists: dataset ${datasetName} does not exist: ${JSON.stringify(
          err
        )}`
      )
      return err
    })

    let table = dataset.table(tableName)
    table.exists().catch(err => {
      console.error(
        `table.exists: table ${tableName} does not exist: ${JSON.stringify(
          err
        )}`
      )
      return err    
    })

    let document = newValue
    document.id = context.params.inloadId

    let row = {
      insertId: context.params.inloadId,
      json: {
        id: context.params.inloadId,
        Inload_ID: document.Inload_ID,
        Code: document.Code,
        Start: document.Start,
        Stop: document.Stop,
        Duration: document.Duration,
        Activity: document.Activity,
        Product: document.Product,
        Delay_Reason: document.Delay_Reason,
        Delay_Cause: document.Delay_Cause,
        Comment: document.Comment,
        Start_Reading_1100_WT_021: document.Start_Reading_1100_WT_021,
        End_Reading_1100_WT_021: document.End_Reading_1100_WT_021,
        Date: document.Date,
        Seconds: document.Seconds,
        Owner: document.Owner,
      },
    }

    return table.insert(row, { raw: true }).catch(err => {
      console.error(`table.insert: ${JSON.stringify(err)}`)
      return err
    })
  })

0 个答案:

没有答案