我一直在尝试使用MongoDb,当我运行脚本进行连接时,它不能,因为密码使用了@
符号.
连接到MongoDb
mongodb://username:password@localhost
但由于我连接到MongoDb的密码使用@
符号,因此符号无法连接@
.
例如;
new MongoClient("mongodb://mongo:p@assword@localhost);
将抛出以下错误;
PHP Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: assword!@localhost:27017: Couldn't get host info for assword!@localhost'
如您所见,它认为@
密码中的第一个是密码和主机的分隔符.
有没有办法连接,并@
在使用MongoClient时允许密码中的符号?
http://uk3.php.net/manual/en/mongoclient.construct.php您可以将用户名和密码作为选项数组传递
new MongoClient("mongodb://localhost:27017", array("username" => "joe", "password" => "test"));