0

我从我的 Node 应用程序连接到 MongoLab 时遇到问题。当我在本地时,一切正常,但是当我将它上传到我的主机(很棒的Clever Cloud,你应该检查一下)时,它没有连接。我复制我的代码和日志。

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");
    });
});

一个日志

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)

我不得不说我很难看到这个问题,因为它在本地运行良好。有人有想法吗?提前致谢。

4

0 回答 0