Phusion Passenger“错误:在连接MongoDB集群时错过了在主机和选项之间划分斜杠”错误

时间:2017-12-14 11:54:33

标签: mongodb nginx meteor connection-string passenger

我已经部署了自己的MongoDB集群。我有一个正在运行的Meteor应用程序,它运行在Nginx之上的Phusion Passenger。在更新Nginx配置文件中的连接字符串后,我收到以下错误:

/<app_directory>/bundle/programs/server/node_modules/fibers/future.js:280
                                                throw(ex);
                                                ^

Error: missing delimiting slash between hosts and options
    at module.exports (/<app_directory>bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/url_parser.js:37:11)
    at connect (/<app_directory>/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/mongo_client.js:289:16)
    at Function.MongoClient.connect (/<app_directory>/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/mongo_client.js:113:3)
    at new MongoConnection (packages/mongo/mongo_driver.js:175:11)
    at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:16)
    at Object.&lt;anonymous&gt; (packages/mongo/remote_collection_driver.js:38:10)
    at Object.defaultRemoteCollectionDriver (packages/underscore.js:784:19)
    at new Mongo.Collection (packages/mongo/collection.js:99:40)
    at AccountsServer.AccountsCommon (packages/accounts-base/accounts_common.js:23:18)
    at new AccountsServer (packages/accounts-base/accounts_server.js:18:5)

当连接字符串之前采用以下格式时,应用程序运行正常:

passenger_env_var MONGO_URL mongodb://db_user:db_password@host_name:port_no/db_name;

但是当我尝试通过以下方式更新连接字符串来连接mu mongoDB集群时,它开始显示错误:

passenger_env_var MONGO_URL mongodb://db_user:'password_with_special_character'@host1_name:port_no,host2_name:port_no/db_name?replicaSet=replica_set_name;

连接字符串或任何其他问题是否有任何问题?

1 个答案:

答案 0 :(得分:2)

这不是Passenger的问题,它只是在配置时传递字符串。通常你会用引号括起整个字符串,如:

passenger_env_var MONGO_URL 'mongodb://db_user:password_with_special_character@host1_name:port_no,host2_name:port_no/db_name?replicaSet=replica_set_name;'

问题是Mongo客户端需要理解字符串,这意味着您需要使用它支持的转义机制,例如URL编码。例如,如果密码包含@,您可以使用%40对其进行网址编码:

# password = p@ssword, @ = url encoded as %40
passenger_env_var MONGO_URL 'mongodb://username:p%40ssword@host:port/dbname';

您可以看到其他特殊字符here的默认网址编码。