node.js - 在它自己的模式中使用模式属性?猫鼬节点js
问题描述
有没有办法可以在它自己的模型中使用模式属性
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”。
解决方案
推荐阅读
- node.js - 用于 botframework 的环聊聊天适配器无法正常工作
- javascript - XMLHttpRequest 有时不起作用
- events - Outlook 添加(日历事件):创建重复事件时的系列 ID
- python - 熊猫在 groupby 上增加一个条件的值
- c# - 有关在 Excel 工作表中查找重复项的帮助
- python - Selenium Python - 获取 chrome 控制台消息
- python-3.x - 使用类从数据框中删除列
- javascript - 如何渲染页面然后在express js中下载它
- c# - 为每个条目使用 Dapper 的 QueryMultiple 和新的 DynamicParameters
- javascript - 使用插件式包扩展 Electron 应用程序开发的架构