我可以创建这样的上限模式: -
var deviceSchema = new mongoose.Schema({
name: String,
vendor: String,
type: String,
backups: [{
date: String,
rawbackup: String
}]
}, {
capped: true,
size: 10485760,
max: 20
})
但我想只限制备份数组。我试过这个: -
var deviceSchema = new mongoose.Schema({
name: String,
vendor: String,
type: String,
backups: [{
date: String,
rawbackup: String
},
{
capped: true,
size: 10485760,
max: 20
}
]
})
它还在增长。我如何限制一个子阵列?
答案 0 :(得分:0)
var deviceSchema = new mongoose.Schema({
name: String,
vendor: String,
type: String,
backups: [{
date: String,
rawbackup: String,
validate: arrayLimit
}]
},
function arrayLimit(val) {
return val.length <= 20;
}
您可以设置架构validation。