I have a problem connecting to MongoLab from my Node app. When I'm in local, everything works fine, but when I'm uploading it on my host (the awesome Clever Cloud, you should check it out), it does not connect. I copy my code and the logs.
var mongo = require('mongodb');
var client = new mongo.Db('tweets', new mongo.Server('ds051077.mongolab.com', 51077, {auto_reconnect: true, 'poolSize': 10}));
client.open(function (error, db) {
if(error) { console.log(error); }
db.authenticate('***', '***', function(err, success) {
if(err) {
console.log("MongoDB failed");
console.log(error);
return;
}
console.log("MongoDB client opened");
});
});
An the logs
2013-03-13 14:13:38 npm install done
2013-03-13 14:13:39 info: socket.io started
2013-03-13 14:13:39 /home/bas/app_1ae17610-f658-4923-87b1-0cc889719794/node_modules/connect-mongo/lib/connect-mongo.js:141
2013-03-13 14:13:39 ^
2013-03-13 14:13:39 throw new Error('Error connecting to database');
2013-03-13 14:13:39 at EventEmitter.emit (events.js:91:17)
2013-03-13 14:13:39 at module.exports.MongoStore.__proto__ (/home/bas/app_1ae17610-f658-4923-87b1-0cc889719794/node_modules/connect-mongo/lib/connect-mongo.js:141:15)
2013-03-13 14:13:39 at Server.connect.connectionPool.on.server._serverState (/home/bas/app_1ae17610-f658-4923-87b1-0cc889719794/node_modules/mongodb/lib/mongodb/connection/server.js:383:7)
2013-03-13 14:13:39 at connection.on.connectionStatus (/home/bas/app_1ae17610-f658-4923-87b1-0cc889719794/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:93:15)
2013-03-13 14:13:39 Error: Error connecting to database
2013-03-13 14:13:39 at EventEmitter.emit (events.js:115:20)
2013-03-13 14:13:39 at Db.open (/home/bas/app_1ae17610-f658-4923-87b1-0cc889719794/node_modules/mongodb/lib/mongodb/db.js:247:16)
2013-03-13 14:13:39 at Socket.EventEmitter.emit (events.js:88:17)
2013-03-13 14:13:39 at Socket._destroy.self.errorEmitted (net.js:327:14)
2013-03-13 14:13:39 at Socket.errorHandler (/home/bas/app_1ae17610-f658-4923-87b1-0cc889719794/node_modules/mongodb/lib/mongodb/connection/connection.js:385:10)
2013-03-13 14:13:39 at process.startup.processNextTick.process._tickCallback (node.js:244:9)
I have to say that I'm struggling to see the problem, as it works fine in local. Does anybody have an idea ? Thanks in advance.