mirror of
https://github.com/franjsco/umbrello-api
synced 2025-06-05 21:59:35 +02:00
Add db
This commit is contained in:
26
src/db/index.js
Normal file
26
src/db/index.js
Normal file
@@ -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;
|
Reference in New Issue
Block a user