-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo.js
35 lines (28 loc) · 865 Bytes
/
mongo.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
const path = require('path')
const mongoose = require('mongoose')
const { readdirSync } = require('fs')
const eventBus = require('~/utils/event-bus')
const isFunction = require('lodash/isFunction')
const blocksModel = require('./modules/builder/models/blocks.model')
const dynamicModelsDir = path.resolve(__dirname, 'modules/builder/models/dynamic')
const OPTIONS = {
keepAlive: 1,
useNewUrlParser: true,
useFindAndModify: false
}
const db = connect()
// TODO: add auto-loader if modules model
require('./models/articles.model')
require('./modules/builder/models/pages.model')
blocksModel()
// load dynamic models
// readdirSync(dynamicModelsDir)
// .forEach(file => require(path.join(dynamicModelsDir, file))())
function connect() {
mongoose.connect(process.env.DB_URL, OPTIONS)
return mongoose.connection
}
module.exports = {
connect,
db
}