首页 > 解决方案 > 类型错误:this.$__setSchema 不是函数

问题描述

我正在尝试在mongodb cloud将数据插入到 mongodb 中。但是在运行代码时,我遇到了 TypeError 之类的错误:this.$__setSchema is not a function。

//Function Called

this.$__setSchema(_schema);

//Function Definition

Document.prototype.$__setSchema = function(schema) {

    schema.plugin(idGetter, { deduplicate: true });
    compile(schema.tree, this, undefined, schema.options);

    // Apply default getters if virtual doesn't have any (gh-6262)
    for (const key of Object.keys(schema.virtuals)) {
        schema.virtuals[key]._applyDefaultGetters();
    }
    if (schema.path('schema') == null) {
        this.schema = schema;
    }
    this.$__schema = schema;
    this[documentSchemaSymbol] = schema;
};

标签: node.jsdatabasemongodbmongoose-schema

解决方案


mongoose.Model ✘</p>

猫鼬模型✔</p>

您需要将模型的第一个字母更改为小写字母。如果你使用大写字母然后你得到这个 ("TypeError: this.$__setSchema is not a function") 错误。


推荐阅读