-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.js
41 lines (38 loc) · 883 Bytes
/
User.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const mongoose = require("mongoose")
const addressSchema = new mongoose.Schema({
street:String,
PostCode: Number,
City: String
})
const userSchema = new mongoose.Schema({
name: String,
age: {
type: Number,
min: 12,
max: 99,
validate: {
validator: v => v >= 12,
message: props => `${props.value} years is below the required age`,
},
},
email: {
type:String,
required: true,
lowercase: true,
},
createdAt: {
immutable: true,
type: Date,
default: () => Date.now(),
},
updatedAt: {
type: Date,
default: () => Date.now(),
},
bestFriend: {type: mongoose.SchemaTypes.ObjectId,
ref: "User"
},
hobbies: [String],
address: addressSchema
})
module.exports = mongoose.model("User",userSchema)