Database config
parent
b1abecc262
commit
51ab76f613
|
@ -0,0 +1,9 @@
|
|||
module.exports = {
|
||||
name: 'api-mooc',
|
||||
host: process.env.HOST_MONGODB || '127.0.0.1:27017',
|
||||
opts: {
|
||||
promiseLibrary: global.Promise,
|
||||
useNewUrlParser: true,
|
||||
useCreateIndex: true,
|
||||
},
|
||||
};
|
|
@ -0,0 +1,13 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const UserSchema = require('../models/user');
|
||||
const NoteSchema = require('../models/note');
|
||||
|
||||
const db = require('./db.config');
|
||||
|
||||
mongoose.connect(`mongodb://${db.host}/${db.name}`, db.opts);
|
||||
|
||||
mongoose.connection.on('connected', () => {
|
||||
mongoose.model('User', UserSchema);
|
||||
mongoose.model('Note', NoteSchema);
|
||||
});
|
Loading…
Reference in New Issue