![](/img/trans.png)
[英]MongooseJS - How to specify a field of an object in an array of a document in Mongoose Populate Virtuals?
[英]Virtuals and populate not showing on mongoose
我在这里做错了吗? 我一直在尝试在派对上显示虚拟我尝试过像“口号”这样的简单虚拟只是为了检查。 我也有人口问题。 我有点讨厌这个,因为它没有给我任何错误或警告,我不知道它背后发生了什么。 有点令人沮丧
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
});
外部 ID 不是 ObjectId 数据类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.