【问题标题】:Argument "data" is not a valid Document. Input is not a plain JavaScript object参数“数据”不是有效的文档。输入不是纯 JavaScript 对象
【发布时间】:2018-11-25 03:47:42
【问题描述】:

我遇到了错误。

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: 'df2b4ad4-6a70-4304-a71f-3a63773ada61', subject_id: 'ABwppHHkzfY1Whp-lCHNnvEcuqvsbMKtZsg_ui9vc4jtpXSiAbh0fNsg6LxGkYq-Va3SOrwcvD-HAs7VQA', entry_date: '2018-06-15', 问卷:1, entry_start_timestamp: '2018-06-15T09:38:10.266Z', entry_end_timestamp: '2018-06-15T09:38:10.266Z', entry_complete:假, 最后一个回答的问题:0, entry_status: '活动' }

如何解决上述问题? json 对象有什么问题吗?

【问题讨论】:

    标签: node.js firebase google-cloud-platform google-cloud-firestore google-cloud-functions


    【解决方案1】:

    您需要调用toJSON 方法。当前,当您需要传递被调用方法的返回值时,您正在将方法的引用传递给set

    改变

    var setAlan = docRef.set(EntryEntity.toJSON);
    

    var setAlan = docRef.set(EntryEntity.toJSON());
    

    【讨论】:

      猜你喜欢
      • 2018-07-19
      • 1970-01-01
      • 2011-08-21
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-02
      • 1970-01-01
      相关资源
      最近更新 更多