I cant connect to MongoDb using mongoose. I have installed MongoDB in my local system
//Import the mongoose module
var mongoose = require('mongoose');
//Set up default mongoose connection`enter code here`
var mongoDB = 'mongodb://localhost/my_database';
mongoose.connect(mongoDB, {
useMongoClient: true
});
//Get the default connection
var db = mongoose.connection;
//Bind connection to error event (to get notification of connection errors)
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
module.exports = mongoose.connection;
getting the error:
// MongoDB connection error: { MongoError: failed to connect to server [localhost:27017] on first connect