-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.js
More file actions
81 lines (62 loc) · 2.25 KB
/
Copy pathmodels.js
File metadata and controls
81 lines (62 loc) · 2.25 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// const mongoose = require('mongoose')
// const userSchema = new mongoose.Schema({
// name: {type: String, required: true},
// email: {type: String, required: true, unique: true},
// password: {type: String, required: true},
// role: {type: String, enum:["user", "admin"]}
// })
// const QuestionSchema = new mongoose.Schema({
// text: { type: String, required: true },
// options: { type: [String], required: true },
// correctOptionIndex: { type: Number, required: true }
// })
// const QuizSchema = new mongoose.Schema({
// title: {type: String, required: true},
// questions: [QuestionSchema]
// })
// const QuizModel = mongoose.model("quiz", QuizSchema)
// const userModel = mongoose.model("user", userSchema)
// async function main(){
// await mongoose.connect('mongodb+srv://songarashagun:gIuJZcNovuXxX5xS@cluster0.v2xwnaf.mongodb.net/')
// const q = await QuizModel.create({
// title: "Quiz"
// })
// q.questions.push({
// title: "what is middleware",
// options: ["workflow mechanism", "special function"]
// })
// await q.save()
// }
// main()
// module.exports = {userModel, QuizModel}
const mongoose = require('mongoose')
const userSchema = new mongoose.Schema({
name: {type: String, required: true},
email: {type: String, unique: true, required: true},
password: {type: String, required: true},
role: {type: String, enum:["user", "admin"]}
})
const questionSchema = new mongoose.Schema({
text: {type: String, required: true},
options: {type:[String], required: true},
correctOptionIndex: {type: String, required: true}
})
const quizSchema = new mongoose.Schema({
title: {type: String, required: true},
questions: [questionSchema]
})
const userModel = mongoose.models("user", userSchema)
const quizModel = mongoose.models("quiz", quizSchema)
async function main(){
await mongoose.connect('mongodb+srv://songarashagun:gIuJZcNovuXxX5xS@cluster0.v2xwnaf.mongodb.net/')
const q = await quizModel.create({
title: "Peanut Quiz",
})
q.questions.push({
title: "Which peanut is this",
options: ["cracked Peanut", "salted peanut", "peanut peanut"]
})
await q.save()
}
main()
module.exports = {userModel, quizModel}