-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_connector.js
37 lines (31 loc) · 959 Bytes
/
db_connector.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
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
mongoose.Promise = Promise;
var usersSchema = new Schema({
email: {type: String, unique: true, required: true},
password: {type: String, required:true},
favouritePlaces: [Schema.Types.ObjectId],
salt: {type: String, required:true}
});
var placesSchema = new Schema({
name: {type: String, required: true},
loc: {
type: { type: String },
coordinates: []
},
type: {type: String, required: true},
description: String,
workingTime: Number,
rating: {type: Number, required: true},
likes: Number
});
// index for GPS coordinates
placesSchema.index({ "loc.coordinates": '2dsphere' });
placesSchema.index({type: 1});
placesSchema.index({rating: 1, likes: 1});
// TODO required and not required fields
exports.models = {
users: mongoose.model('user', usersSchema, 'users'),
places: mongoose.model('place', placesSchema, 'places')
};
mongoose.connect('localhost:27017/takeahike');