From eb6f2066df734ec172c32d5d863a5c0fd6ff901e Mon Sep 17 00:00:00 2001 From: Francesco Esposito <33671357+frsposito@users.noreply.github.com> Date: Thu, 22 Aug 2019 17:43:56 +0200 Subject: [PATCH] Add db --- src/db/index.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/db/index.js diff --git a/src/db/index.js b/src/db/index.js new file mode 100644 index 0000000..c8fd7de --- /dev/null +++ b/src/db/index.js @@ -0,0 +1,26 @@ +import mongoose from 'mongoose'; + +import citySchema from './city.model'; +import logger from '../logger'; +import config from '../config'; + + +const options = { + useNewUrlParser: true, + user: config.database.user, + pass: config.database.password, +}; + +mongoose.connect(config.database.host, options); + +mongoose.set('useFindAndModify', false); + +const db = mongoose.connection; + + +db.on('error', (err) => logger.error(err)); + +db.once('open', () => logger.info('Database connected')); + + +export default citySchema;