我在这里做错什么了吗?我一直在尝试在Party上显示虚拟图像,而我只是尝试检查“口号”之类的简单虚拟图像。我也有人口问题。我有点讨厌这个cuz,它既不会抛出任何错误,也不会警告我,我也不知道它背后发生了什么。有点令人沮丧
const mongoose = require('mongoose');
mongoose.set("debug", true);
const partySchema = mongoose.Schema({
name: {
type: String,
required: [true, 'Please provide a party'],
unique: [true, 'Party already exists. Please try another party name'],
maxLength: [20, 'Party Name should be less than 20 characters'],
minLength: [4, 'Party Name should be greater than 4 characters']
},
slogan:{
type: String,
required: [true, 'Please provide a slogan'],
maxLength: [20, 'Party Name should be less than 20 characters'],
minLength: [5, 'Party Name should be greater than 5 characters']
},
createdAt:{
type: Date,
default: Date.now()
}
},{
toObject: {
virtuals: true
}
,toJSON: {
virtuals: true
}
});
partySchema.virtual('slogans').get(function () {
// use an ordinary function so you can get the "this"
return this.slogan
});
答案 0 :(得分:0)
外部标识不是ObjectId数据类型