我收到以下错误。
Error: Argument "data" is not a valid Document. Input is not a plain JavaScript object.
at Object.exports.(anonymous function) [as isDocument] (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/validate.js:86:15)
at WriteBatch.set (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/write-batch.js:286:14)
at DocumentReference.set (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/reference.js:420:8)
at PainEntryService.createEntry (/user_code/services/entry-service.js:19:30)
at /user_code/services/intentService.js:22:36
at Function.<anonymous> (/user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:146:23)
at next (native)
at /user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:22:71
at __awaiter (/user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:18:12)
at Function.handler (/user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:84:16)
我使用下面的代码创建文档
var docRef = this.dbManager.collection('tetst).doc(subjectId);
var setAlan = docRef.set(EntryEntity.toJSON);
我在toJSON方法中有以下代码
public toJSON(): testEntry {
let returnJSON = {
"entry_id": this.entry_id,
"subject_id": this.subject_id,
"entry_date": this.entry_date,
"questionnaire": this.questionnaire,
"entry_start_timestamp": this.entry_start_timestamp,
"entry_end_timestamp": this.entry_end_timestamp,
"entry_complete": this.entry_complete,
//"responses": this.responses,
"last_answered_question" : this.last_answered_question,
"entry_status" : this.entry_status
}
return returnJSON;
}
我在上面的方法中构建了json对象。如果我打印json对象,我将得到低于内容
{entry_id:&#39; df2b4ad4-6a70-4304-a71f-3a63773ada61&#39;, subject_id:&#39; ABwppHHkzfY1Whp-lCHNnvEcuqvsbMKtZsg_ui9vc4jtpXSiAbh0fNsg6LxGkYq-Va3SOrwcvD-HAs7VQA&#39;, entry_date:&#39; 2018-06-15&#39;, 问卷:1, entry_start_timestamp:&#39; 2018-06-15T09:38:10.266Z&#39;, entry_end_timestamp:&#39; 2018-06-15T09:38:10.266Z&#39;, entry_complete:false, last_answered_question:0, entry_status:&#39;有效&#39; }
如何解决上述问题? json对象有什么问题吗?
答案 0 :(得分:0)
您需要调用toJSON
方法。当您需要传递被调用方法的返回值时,您正在将方法的引用传递给set
。
更改
var setAlan = docRef.set(EntryEntity.toJSON);
到
var setAlan = docRef.set(EntryEntity.toJSON());