const { version } = require("mongoose")
let mongoose = require("./db")
let Schema = mongoose.Schema
let userSchema = new Schema({
name:{
type:String,
require:true,
minlength:2
},
password:{
type:String,
},
userInfoId:{
type:Schema.Types.ObjectId,
ref:"userInfo"
}
})
let userInfoSchema = new Schema({
nickname:{
type:String,
minlength:2
},
age:{
type:Number,
max:150,
min:1
},
sex:{
type:String,
default:"男"
},
phone:{
type:String,
match:/^1[35678]\d{9}$/
},
email:{
type:String,
match:/^[a-zA-Z0-9][a-zA-Z0-9_]+\@[a-zA-Z0-9]+\.(com|cn|net|com.cn)$/i
},
createTime:{
type:Date,
default:new Date()
},
user:{
type:Schema.Types.ObjectId,
ref:"user"
}
},{versionKey:false})
let categorySchema = new Schema({
name:String,
level:Number,
pid:{
type:Schema.Types.ObjectId,
ref:"category"
}
})
const userModel = mongoose.model("user",userSchema,"user")
const userInfoModel = mongoose.model("userInfo",userInfoSchema,"userInfo")
const categoryModel = mongoose.model("category",categorySchema,"category")
// userInfoModel.create({
// nickname:"十一",
// age:18,
// sex:"男",
// phone:"13400405244",
// email:"13400405244@163.com",
// user:"63f60415413fa76ad888aaf7"
// })
// categoryModel.create({
// name:"手枪",
// level:3,
// pid:'63f70749042b360023cec927'
// })
module.exports = {
userModel,
userInfoModel,
categoryModel
}