Мне бы очень хотелось узнать, где я ошибаюсь, используя этот фрагмент кода.Я получаю эту ошибку.«Ошибка: не удалось выполнить функцию. Детали: невозможно прочитать свойство« Inload_ID »из неопределенного» * 1001 *
Я использовал это как шаблон.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
})
})