字符串最小长度
maxlength: 20 字符串最大长度
min: 2 数值最小为2
max: 100 数值最大为100
enum: [‘html’, ‘css’, ‘javascript’, ‘node.js...// 必选字段
required: [true, '请传入文章标题'],
// 字符串的最小长度
minlength: [2, '文章长度不能小于...String,
// 枚举 列举出当前字段可以拥有的值
enum: {
values: ['html', 'css', 'javascript', 'node.js...使用id对集合进行关联
使用populate方法进行关联集合查询
集合关联实现
// 用户集合
const User = mongoose.model('User', new mongoose.Schema..., ref: 'User' }
}));
//联合查询
Post.find()
.populate('author')
.then((err, result) => console.log