UBUNTU下MONGODB出现PHP Fatal error: Uncaught exception 'MongoConnectionException' with message 和 Authentication failed on database 'admin' with username

MONGO 远程连接服务器,出现:

PHP Fatal error:  Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: 63.141.xx.xxx:27017: Authentication failed on database 'admin' with username 'xxx': auth fails' in /var/www/data/update_data.php:25
Stack trace:#0 /var/www/data/update_data.php(25): Mongo->__construct('mongodb://seole...')
#1 {main}

 

Authentication failed on database 'admin' with username

我明明连接的是XXX数据集合。 不是admin数据库。为毛出现连接Admin失败。

GOOGLE,原来是有些版本的mongo 搭配 linux后,如果不指定连接数据集,默认连接的是admin数据集,所以在连接字符串中就得指明要连接数据集。

代码由
$mongo_server = "mongodb://username:passwd@63.141.xx.xxx:27017";
$m_f = new Mongo($mongo_server); //
$db_f = $m_f->eTao;
$collection_f = $db_f->etao_data;

改为


$mongo_server = "mongodb://username:passwd@63.141.xx.xxx:27017/eTao";
$m_f = new Mongo($mongo_server); //
$db_f = $m_f->eTao;
$collection_f = $db_f->etao_data;

 

posted @ 2013-09-23 19:13  群叔  阅读(3792)  评论(0编辑  收藏  举报