Je ne peux pas me connecter à MongoDb en utilisant mongoose. J'ai installé MongoDB dans mon système localne peut pas se connecter à MongoDb en utilisant mongoose. MongoDB installé dans mon système local
//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;
obtenir l'erreur:
// MongoDB connection error: { MongoError: failed to connect to server [localhost:27017] on first connect
essayez d'utiliser 'mongodb: //0.0.0.0: 27017/my_database' – Vignesh