Skip to content
On this page

设计数据库模型

定义模型,也就是数据表

在{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

数据类型

数据类型
Number数字
String字符串
Boolean布尔值
ObjectId对象 ID
Array数组
Date日期
Buffer二进制
Mixed混合类型
沪ICP备20006251号-1