Mongodb 使用远程Mongo DB时无法加载Sails
我的Sail应用程序在连接到本地mongo db时运行,但当我尝试使用托管在Module的db进行连接时,它无法正常加载 我已经正确设置了连接,并通过it IDE进行了测试Mongodb 使用远程Mongo DB时无法加载Sails,mongodb,sails.js,Mongodb,Sails.js,我的Sail应用程序在连接到本地mongo db时运行,但当我尝试使用托管在Module的db进行连接时,它无法正常加载 我已经正确设置了连接,并通过it IDE进行了测试 connections.js: // MONGO DB reference for the database cogspeed: { adapter : 'sails-mongo', //host : 'localhost', host : 'novus.mod
connections.js:
// MONGO DB reference for the database
cogspeed: {
adapter : 'sails-mongo',
//host : 'localhost',
host : 'novus.modulusmongo.net',
port : 27017,
user : '*********',
password : '***********',
database : '**********'
},
我得到的错误是:
C:\Projects\gmm\cogspeed>sails lift
info: Starting app...
error: A hook (`orm`) failed to load!
error: Error: failed to connect to [localhost:27017]
at null.<anonymous> (C:\Projects\gmm\cogspeed\node_modules\sails-mongo\node_modules\mongodb\lib\mongodb\conne
ction\server.js:553:74)
at EventEmitter.emit (events.js:106:17)
at null.<anonymous> (C:\Projects\gmm\cogspeed\node_modules\sails-mongo\node_modules\mongodb\lib\mongodb\conne
ction\connection_pool.js:140:15)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (C:\Projects\gmm\cogspeed\node_modules\sails-mongo\node_modules\mongodb\lib\mongodb\con
nection\connection.js:512:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickDomainCallback (node.js:459:13)
C:\Projects\gmm\cogspeed>sails lift
信息:正在启动应用程序。。。
错误:无法加载挂钩(`orm`)!
错误:错误:无法连接到[localhost:27017]
在空。(C:\Projects\gmm\cogspeed\node\u modules\sails mongo\node\u modules\mongodb\lib\mongodb\conne
Action\server.js:553:74)
在EventEmitter.emit(events.js:106:17)
在空。(C:\Projects\gmm\cogspeed\node\u modules\sails mongo\node\u modules\mongodb\lib\mongodb\conne
action\connection_pool.js:140:15)
在EventEmitter.emit(events.js:98:17)
在插座上。(C:\Projects\gmm\cogspeed\node\u modules\sails mongo\node\u modules\mongodb\lib\mongodb\con
nection\connection.js:512:10)
位于Socket.EventEmitter.emit(events.js:95:17)
net.js:441:14
在进程中。_tickDomainCallback(node.js:459:13)
为什么Sails还在看localhost
提前谢谢 config/local.js文件仍然有一个指向本地主机的mongo适配器。请验证您的密码不包含“@”字符。由于节点mongodb native的当前实现,它会弄乱您的连接字符串。我也有同样的问题。事实证明,在connections.js中使用同一适配器有多个连接会导致此问题。如果错误显示
error: Error: failed to connect to [localhost:27017]
然后,Mongo没有运行。您可以使用命令启动它
mongod
愚蠢的错误,但也会发生
如果错误为error:
MongoError:auth失败
,则此解决方案可能适用于您:Sails still(v 0.11.0)在/config/connections.js配置文件中存在多个相同类型的适配器的问题。在模块上部署后,我也遇到了同样的问题,支持人员无法帮助我。我花了几个小时试着调试它。。。。但解决方法非常简单。不要将db连接参数放入connections.js,而是直接将它们放入特定于环境的配置文件中,如下所示:
// config/env/development.js
module.exports = {
connections : {
mongo: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
database: 'your-db-name'
},
},
// your other dev configs
};
生产:
// config/env/development.js
module.exports = {
connections : {
mongo: {
adapter: 'sails-mongo',
host: 'your-remote-mongo-host',
port: 27017,
user: 'your-remote-user',
password: 'your-remote-db-password',
database: 'your-remote-db-name'
},
},
// your other dev configs
};
您的/config/models.js如下所示:
module.exports = {
connection : 'mongo',
// your other model configs
};
PS:这个问题已经向sails.js团队报告了,你的
/config/models.js
文件是什么样子的?/config/models.js是:module.exports.models={///你的应用程序的默认连接//即你的一个应用程序连接的名称(请参见config/connections.js
)///(默认为localDiskDb)连接:'cogspeed mongo'};罪魁祸首是/config/local.js文件,该文件有一个指向本地主机的mongo适配器。是的。我刚刚对localDiskDb
进行了注释,并留下了我的someMongodbServer
,该问题仍然存在于Sailsjs的v0.11中。