Appearance
设计数据库模型
定义模型,也就是数据表
在{workplace}/app/model/article.js 定义数据表
javascript
"use strict";
module.exports = (app) => {
const mongoose = app.mongoose;
const Schema = mongoose.Schema;
const RoleSchema = new Schema({
role: {
type: String,
index: {
unique: true,
}, // 该字段为唯一字段
require: true, // 必填项
},
roleName: {
type: String,
require: true,
},
// 备注
note: {
type: String,
require: true,
},
});
return mongoose.model("Role", RoleSchema, "role");
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
数据类型
数据类型 | |
---|---|
Number | 数字 |
String | 字符串 |
Boolean | 布尔值 |
ObjectId | 对象 ID |
Array | 数组 |
Date | 日期 |
Buffer | 二进制 |
Mixed | 混合类型 |