-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_config.js
41 lines (28 loc) · 873 Bytes
/
db_config.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
var db_string = 'mongodb://127.0.0.1/quiz';
var mongoose = require('mongoose').connect(db_string);
var db = mongoose.connection;
db.on('error',console.error.bind(console,'Erro ao conectar no banco'));
db.once('open',function(){
var userSchema = mongoose.Schema({
fullname: String,
email: String,
password: String,
created_at: { type: Date, default: Date.now },
updated: Date
});
exports.User = mongoose.model('User',userSchema);
var itemQuestaoSchema = mongoose.Schema({
alternativa: String,
itemCorreto: Boolean
});
var questaoSchema = mongoose.Schema({
enunciado: String,
tipo: String,
autor: { type: mongoose.Schema.ObjectId, ref: 'User' },
categoria: String,
itens:[itemQuestaoSchema],
updated: Date,
created_at: { type: Date, default: Date.now }
});
exports.Questao = mongoose.model('Question',questaoSchema);
});