-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathschema-validation.js
More file actions
46 lines (46 loc) · 1.66 KB
/
schema-validation.js
File metadata and controls
46 lines (46 loc) · 1.66 KB
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
42
43
44
45
46
db.createCollection("student_with_validation", {
validator: {
$jsonSchema: {
bsonType: "object",
required: [
"firstName", "lastName", "country", "isStudentActive",
"email", "totalSpentInBooks", "gender"
],
properties: {
firstName: {
bsonType: "string",
description: "must be a string and is required",
},
lastName: {
bsonType: "string",
description: "must be a string and is required",
},
country: {
bsonType: "string",
description: "must be a string and is required",
},
isStudentActive: {
bsonType: "bool",
description: "must be a bool and is required"
},
gender: {
enum: ["M", "F"],
description: "can only be one of the enum values and is required",
},
favouriteSubjects: {
bsonType: "array",
description: "favourite subject is required",
},
totalSpentInBooks: {
bsonType: "double",
description: "must be a double if the field exists",
},
email: {
bsonType : "string",
pattern : "@amigoscode\.com$",
description: "must be a string and match the regular expression pattern"
},
},
},
}
});