获取"TypeError:schema.virtual(...).get不是函数" [英] Getting "TypeError: schema.virtual(...).get is not a function"
本文介绍了获取"TypeError:schema.virtual(...).get不是函数"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试定义架构时收到此错误.
I get this error while I try to define my schema.
错误:
node_modules/mongoose/lib/plugins/idGetter.js:12
schema.virtual('id').get(idGetter);
TypeError: schema.virtual(...).get is not a function
at module.exports (/Users/g.paradiso/dev/albumin-diet/node_modules/mongoose/lib/plugins/idGetter.js:12:26)
模式:
export const albumSchema = new Schema({
id: {
spotify: String
},
tags: [{ type: Schema.Types.ObjectId, ref: "Tag" }],
}, { timestamps: true });
推荐答案
出现此错误是因为我有一个名为id
的字段,该字段可能覆盖了内部_id
字段.
The error was raised because I had a field called id
that probably was overriding the internal _id
field.
我决定在以下位置更改架构:
I resolved changing my schema in:
export const albumSchema = new Schema({
publicId: {
spotify: String
},
tags: [{ type: Schema.Types.ObjectId, ref: "Tag" }],
}, { timestamps: true });
这篇关于获取"TypeError:schema.virtual(...).get不是函数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文