-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
34 lines (28 loc) · 793 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
const mongoose = require('mongoose')
const Counter = require('./models/counter')
const Url = require('./models/url')
const url = 'mongodb://127.0.0.1:27017'
mongoose
.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
})
.then(() => {
console.log('up and running')
Url.deletePrev({}, () => {
console.log('url collection removed')
})
Counter.deletePrev({}, () => {
console.log('removing counter collection')
const counter = new Counter({ _id: 'url_count', count: 5000 })
counter.save((err) => {
if (err) return console.log(err)
console.log('saving counter')
})
})
})
.catch((err) => {
console.log('not connecting to database')
})