获取“TypeError:schema.virtual(...).get 不是函数”

gia*_*ise 0 javascript mongoose node.js

当我尝试定义架构时出现此错误。

错误:

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)
Run Code Online (Sandbox Code Playgroud)

架构:

export const albumSchema = new Schema({
  id: {
    spotify: String
  },
  tags: [{ type: Schema.Types.ObjectId, ref: "Tag" }],
}, { timestamps: true });
Run Code Online (Sandbox Code Playgroud)

gia*_*ise 5

引发错误是因为我有一个名为的字段id可能会覆盖内部_id字段。

我决定更改我的架构:

export const albumSchema = new Schema({
  publicId: {
    spotify: String
  },
  tags: [{ type: Schema.Types.ObjectId, ref: "Tag" }],
}, { timestamps: true });
Run Code Online (Sandbox Code Playgroud)