node.js - 类型错误: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;
};
解决方案
mongoose.Model ✘</p>
猫鼬模型✔</p>
您需要将模型的第一个字母更改为小写字母。如果你使用大写字母然后你得到这个 ("TypeError: this.$__setSchema is not a function") 错误。
推荐阅读
- hive - 有没有我们不想重用 tez 容器的场景?
- python - 根据具有特定条件的另一个行值更新行值,pandas
- r - 如何从 HTML 代码中提取特定的数字字符串?
- python - 如何从 Python 中的列表中删除字符串
- javascript - 在 Mapbox GLJS 中向 swipetool 添加一个额外的层?
- go - go中的字数
- microsoft-teams - Microsoft 团队频道删除事件侦听器
- javascript - 如何正确处理 jquery 事件绑定?
- r - 通过多个键对行进行分组并获得分类的数值和模式的平均值
- python - 使用集合文字更快地设置包含