有一种方法可以在其自己的模型中使用架构属性
var mongoose = require("mongoose");
//====================================================
// Schema
//====================================================
var bookSchema = new mongoose.Schema({
name: String,
image: String,
summary: String,
author: String,
genre: String,
publisher: String,
available: Number,
submitted: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User" //model name
},
username: String
},
reviews: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Review"
}
],
reserves: {
type: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Reserve"
}],
validate: [arrayLimit, '{PATH} exceeds the limit of 5']
}
});
function arrayLimit(val) {
return val.length <= 5;
}
module.exports = mongoose.model("Book", bookSchema);
函数arraylimit中的。我正在尝试将bookSchema中的“ 5”替换为“ available”属性。