-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
45 lines (38 loc) · 1.13 KB
/
db.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
42
43
44
45
var mongoose = require('mongoose');
var config = require('./secret.json');
var bcrypt = require('bcrypt');
var userSchema = new mongoose.Schema({
username: String,
passwordHash: String,
salt: String,
email: String,
role: String
}, {collection: "users"});
var productSchema = new mongoose.Schema({
name: String,
description: String,
imagePath: String,
tasteRating: {type: Number, min: 1, max: 5},
powerRating: {type: Number, min: 1, max: 5},
dustRating: {type: Number, min: 1, max: 5},
numberOfRatings: Number
}, {collection: "products"});
var commentSchema = new mongoose.Schema({
username: String,
productID: String,
comment: String,
date: Date
}, {collection: "comments"});
var ratingSchema = new mongoose.Schema({
username: String,
productID: String,
tasteRating: Number,
powerRating: Number,
dustRating: Number,
}, {collection: "ratings"});
mongoose.model('User', userSchema);
mongoose.model('Product', productSchema);
mongoose.model('Comment', commentSchema);
mongoose.model('Rating', ratingSchema);
mongoose.connect(config.url);
module.exports.mongoose = mongoose;