-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
43 lines (31 loc) · 830 Bytes
/
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
// db.js
const mongoose = require('mongoose');
const Entry = new mongoose.Schema({
// createdBy: {type: String, required:true},
title: String,
text: String,
date: String
});
const Coordinate = new mongoose.Schema({
latlng: String,
cookie: String,
memories: [Entry],
address: String
});
let dbconf;
if (process.env.NODE_ENV === 'PRODUCTION') {
// if we're in PRODUCTION mode:
const fs = require('fs');
const path = require('path');
const fn = path.join(__dirname, 'config.json');
const data = fs.readFileSync(fn);
const conf = JSON.parse(data);
dbconf = conf.dbconf;
} else {
// if we're not in PRODUCTION mode, then use
dbconf = 'mongodb://localhost/mapdiary';
}
// mongoose.model('User', User);
mongoose.model('Coordinate', Coordinate);
mongoose.model('Entry', Entry);
mongoose.connect(dbconf);