一、用户表的设计
字段名 | 数据类型 | - |
---|---|---|
_id | String | 用户id |
avatarUrl | String | 用户头像 |
nickname | String | 用户昵称 |
birthDate | String | 用户出生日期 |
username | String | 用户名 |
password | String | 用户密码(加密) |
friends | Arrary | 用户好友 |
address | Object | 用户地址 |
二、nodejs代码
2.1 创建用户表模型
const mongoose = require('mongoose')
const userSchema = new mongoose.Schema({
avatarUrl: String,
address: Object,
nickname: {
type: String,
required: true,
},
birthDate: {
type: String,
required: true,
},
username: {
type: String,
required: true,
},
password: {
type: String,
required: true,
},
friends: Array,
})
const userModel = mongoose.model('user', userSchema)
module.exports = userModel
2.2 字段验证 安装express-validator库
2.2 验证规则
2.4 路由