Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: this.$__setSchema is not a function

I am trying to insert data into mongodb at mongodb cloud. But while running the code i am getting error like 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;
};
like image 401
Shivam Kumar Avatar asked Oct 21 '25 14:10

Shivam Kumar


1 Answers

mongoose.Model ✘

mongoose.model ✔

You need to change the first letter of Model to small letter. if you use the capital letter and then you get this ("TypeError: this.$__setSchema is not a function") error.

like image 130
chitraarasu Avatar answered Oct 23 '25 04:10

chitraarasu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!