What am I missing?
(我想念什么?)
Trying to use console.log() to debug a Firestore function.(尝试使用console.log()调试Firestore函数。)
The firestore function logs show the error details, however I cannot seem to get console.log() to add debugging message to the Log:(firestore函数日志显示错误详细信息,但是我似乎无法使console.log()向日志添加调试消息:)
Here is the function Log error:
(这是函数Log错误:)
TypeError: Cannot read property 'document' of undefined
at exports.updateIndex.functions.firestore.document.onCreate.event (/srv/index.js:13:36)
at cloudFunction (/srv/node_modules/firebase-functions/lib/cloud-functions.js:131:23)
at /worker/worker.js:825:24
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
Here is the function code in index.js:
(这是index.js中的功能代码:)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.updateIndex = functions.firestore
.document('Documents/{Name}')
.onCreate(event => {
const documentId = event.params.document.id;
const id = this.document ? this.document.id : '';
console.log("Update Index for Doc", document);
const document = event.after.data();
console.log("docId",documentId,"id",id);
const searchableIndex = newFunction(document)
const indexedDocument = { ...document, searchableIndex }
const db = admin.firestore()
return db.collection('Documents').doc(document.id).set(indexedDocument, { merge: true })
})
function newFunction(document) {
return createIndex(document.Name);
}
function createIndex(document) {
const arr = Name.toLowerCase().split('');
const searchableIndex = {}
console.log("Creating Index");
let prevKey = '';
for (const char of arr) {
const key = prevKey + char;
searchableIndex[key] = true
prevKey = key
}
console.log("Create docId",documentId,"id",id);
return searchableIndex
}
Thanks for any ideas!
(感谢您的任何想法!)
ask by tomN translate from so