0
I’m having trouble connecting to Mongodb.
Follows the code:
var express= require('express');
var app= express();
var bodyParser= require('body-parser');
var db_string= 'mongodb://localhost/teste'
var mongoose= require('mongoose');
var db= mongoose.connection;
mongoose.connect(db_string);
db.on('error', console.error.bind(console, 'Erro ao conectar no banco'));
db.once('open', function(){
var testeSchema= mongoose.Schema({
name: String,
});
});
Error displayed on console:
Erro ao conectar no banco { [MongoError: connect ECONNREFUSED] name: 'MongoError', message: 'connect ECONNREFUSED' }
You can show me improvements to fix the problem with these solutions?
– Away
I tried to test run a simple command from the terminal: show dbs and got the following return: Error: couldn’t connect to server 127.0.0.1:27017 at src/Mongo/shell/Mongo.js:145 Exception: connect failed
– Away
You executed the server command (mongod) 1st?
– nothing
I was having trouble installing Mongodb, reinstalled it and the problem was solved.
– Away