gpt4 book ai didi

mongodb - 连接 MongoDB 集群时 Phusion Passenger "Error: missing delimiting slash between hosts and options"错误

转载 作者:可可西里 更新时间:2023-11-01 10:13:36 32 4
gpt4 key购买 nike

我已经部署了自己的 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;

是连接字符串有问题还是其他什么问题?

最佳答案

这不是 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 对其进行 URL 编码:

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

可以看到其他特殊字符的默认URL编码here .

关于mongodb - 连接 MongoDB 集群时 Phusion Passenger "Error: missing delimiting slash between hosts and options"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47812768/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com