1const mongoose = require('mongoose');
2mongoose.connect('mongodb://localhost/my_database', {
3 useNewUrlParser: true,
4 useUnifiedTopology: true,
5 useFindAndModify: false,
6 useCreateIndex: true
7 })
8 .then(()=> console.log('connect'))
9 .catch((error) => console.error(error));
1const mongoose = require('mongoose');
2
3mongoose.connect('mongodb://localhost:27017/twitter', {
4 useNewUrlParser: true,
5 useUnifiedTopology: true
6});
7
8const db = mongoose.connection;
9
10db.on('error', console.error.bind(console, 'connection error:'));
11db.once('open', function () {
12 console.log("Database Connected !!!");
13});
14
15module.exports = db;