Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获得;TypeError:schema.virtual(…).get不是函数;_Javascript_Node.js_Mongoose - Fatal编程技术网

Javascript 获得;TypeError:schema.virtual(…).get不是函数;

Javascript 获得;TypeError:schema.virtual(…).get不是函数;,javascript,node.js,mongoose,Javascript,Node.js,Mongoose,我在尝试定义模式时遇到此错误 错误: 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/plug

我在尝试定义模式时遇到此错误

错误:

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
的字段,该字段可能覆盖了内部
\u id
字段

我决定在以下位置更改我的架构:

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

出现错误是因为我有一个名为
id
的字段,该字段可能覆盖了内部
\u id
字段

我决定在以下位置更改我的架构:

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

我发现这主要是由于定义了架构中已经定义的虚拟字段名。在您的案例中,id已在架构中定义,更改架构中已定义属性的名称或更改虚拟字段名称应该可以

比如说

export const albumSchema=新模式({
//从id更改为可能的唱片集\u id
身份证:{
spotify:String
},
标记:[{type:Schema.Types.ObjectId,ref:“Tag”}],
},{时间戳:true});
//将虚拟字段名id更改为spotify_id也可以
schema.virtual('id',{…})

我发现这主要是由于定义了架构中已经定义的虚拟字段名。在您的案例中,id已在架构中定义,更改架构中已定义属性的名称或更改虚拟字段名称应该可以

比如说

export const albumSchema=新模式({
//从id更改为可能的唱片集\u id
身份证:{
spotify:String
},
标记:[{type:Schema.Types.ObjectId,ref:“Tag”}],
},{时间戳:true});
//将虚拟字段名id更改为spotify_id也可以
schema.virtual('id',{…})