Mongodb权限验证失败

时间:2017-01-14 05:56:34

标签: php mongodb

我可以通过远程访问mongodb获得成功。用这个:

try {
    $mon = new MongoClient('mongodb://user:user@121.21.147.245:27017');
}catch(MongoConnectionException $e) {
    exit("Failed to connect to database :". iconv('GB2312','UTF-8', $e->getMessage()));
}

但我把程序和mongodb放在同一台服务器上,链接再次提示权限不正确。

try {
    $mon = new MongoClient('mongodb://user:user@121.21.147.245:27017');
}catch(MongoConnectionException $e) {
    exit("Failed to connect to database :". iconv('GB2312','UTF-8', $e->getMessage()));
}

使用本地地址或

try {
    $mon = new MongoClient('mongodb://user:user@127.0.0.1:27017');
}catch(MongoConnectionException $e) {
    exit("Failed to connect to database :". iconv('GB2312','UTF-8', $e->getMessage()));
}

提示此错误

Failed to connect to database :
Failed to connect to: 121.21.147.245:27017: 
Authentication failed on database    'admin' with username 'user': auth failed

Failed to connect to database :
Failed to connect to: 127.0.0.1:27017: 
Authentication failed on database    'admin' with username 'user': auth failed

为什么可以使用远程连接,但不能使用本地?

0 个答案:

没有答案