You are not getting into the console.log
cause your code is breaking at this line:
(您没有进入console.log
因为您的代码在此行中断:)
const id = this.document ? this.document.id : '';
since it cannot find this
, it will try to set this.document.id
and crash.
(由于找不到this
,它将尝试设置this.document.id
并崩溃。)
so to your specific question, console.log
works as you think it does, just make sure you code reach that log first, you can move the log before the error line and you should get it
(因此,对于您的特定问题, console.log
可以按您认为的方式工作,只需确保您的代码首先到达该日志,就可以将日志移到错误行之前,应该获取它。)
exports.updateIndex = functions.firestore
.document('Documents/{Name}')
.onCreate(event => {
const documentId = event.params.document.id;
/*********
HERE IT WILL WORK
********/
console.log(documentId) // Cool!
const id = this.document ? this.document.id : ''; // ERROR LINE
console.log("Update Index for Doc", document);
const document = event.after.data();
console.log("docId",documentId,"id",id); // WONT WORK
const searchableIndex = newFunction(document)
const indexedDocument = { ...document, searchableIndex }
const db = admin.firestore()
return db.collection('Documents').doc(document.id).set(indexedDocument, { merge: true })
})
The other thing you need to figure out is what does this
refers to?
(你需要弄清楚的另一件事是什么呢this
是指?)
?? I think you have an error of concepts there (??我认为您那里的概念有误)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…