Not sure what to do, can't connect when i run >>node index.js in git shell. it gives me the following
LoL RPG started on port 8080 connection error: [Error: failed to connect to [undefined:27017]]
/* ==== MONGODB ==== */
var mongoose = require('mongoose');
var db = require('./config/db.js');
mongoose.connect(db.url);
mongoose.connection.on('error', console.error.bind(console, 'connection error:'));
mongoose.connection.once('open', function() { console.log("Mongo DB connected!"); });
/* ==== config/db.js ==== */
module.exports = "mongodb://<username>:<username>@ds052837.mongolab:52837/lolrpg";
Not sure what to do, can't connect when i run >>node index.js in git shell. it gives me the following
LoL RPG started on port 8080 connection error: [Error: failed to connect to [undefined:27017]]
/* ==== MONGODB ==== */
var mongoose = require('mongoose');
var db = require('./config/db.js');
mongoose.connect(db.url);
mongoose.connection.on('error', console.error.bind(console, 'connection error:'));
mongoose.connection.once('open', function() { console.log("Mongo DB connected!"); });
/* ==== config/db.js ==== */
module.exports = "mongodb://<username>:<username>@ds052837.mongolab.:52837/lolrpg";
Share
Improve this question
edited May 8, 2015 at 20:03
vgoff
11.3k3 gold badges41 silver badges58 bronze badges
asked Jan 26, 2015 at 20:59
Marvine ChiMarvine Chi
1771 gold badge3 silver badges10 bronze badges
3
-
2
Simply based on the error, it's trying to connect to a mongoDB url set to
undefined
. 27017 is the default mongoDB port. docs.mongodb/manual/reference/default-mongodb-port But posting literally ANY code would help a lot. – Tony Commented Jan 26, 2015 at 21:10 - 1 @Tony do these codes help? – Marvine Chi Commented Jan 26, 2015 at 22:16
- I assume you did not start MongoDB – Vitalii Zurian Commented Jan 27, 2015 at 12:33
1 Answer
Reset to default 7The problem here is that your db
variable in the first section of code is referring to the connection string, but you try to access a url
property on it, which ends up being undefined.
Replace mongoose.connect(db.url)
with mongoose.connect(db)
.
Alternatively, in db.js, you can replace module.exports = ...
with module.exports.url = ...
.