We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
用mongo子账号在客户端可以连接到某个db的,所以权限没问题的,同样的问题在以下链接看到了 tp5 mongodb Authentication failed(认证失败) 建议connector/Mongo.php 135行dsn增加database的配置 修改前:
connector/Mongo.php
dsn
database
$config['dsn'] = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
修改后
$config['dsn'] = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '').($config['database'] ? "/{$config['database']}" : '');
The text was updated successfully, but these errors were encountered:
#79
Sorry, something went wrong.
根据 #79 的建议增加params参数问题解决,不过感觉不是很方便,容易踩坑,希望下次踩坑的同学看到这个讨论,最后database.php配置如下:
database.php
<?php use think\facade\Env; return [ // 默认使用的数据库连接配置 'default' => Env::get('database.driver', 'mysql'), // 数据库连接配置信息 'connections' => [ 'mysql' => [ ... ], // 更多的数据库配置信息 'mongo' => [ // 数据库类型 'type' => '\think\db\connector\Mongo', // 设置查询类 'query' => '\think\db\Mongo', // 服务器地址 'hostname' => Env::get('mongo.hostname', '127.0.0.1'), // 集合名 'database' => Env::get('mongo.database', 'efiles'), // 用户名 'username' => Env::get('mongo.username', 'efile'), // 密码 'password' => Env::get('mongo.password', ''), // 端口 'hostport' => Env::get('mongo.hostport', 27017), 'params' => [ 'authSource' => Env::get('mongo.database', 'efiles'), ], ], ], // 自定义时间查询规则 'time_query_rule' => [], // 自动写入时间戳字段 'auto_timestamp' => 'timestamp', // 时间字段取出后的默认时间格式 'datetime_format' => 'Y-m-d H:i:s', ];
最主要的是在mongo的连接配置增加:
'params' => [ 'authSource' => Env::get('mongo.database', 'efiles'), ],
No branches or pull requests
用mongo子账号在客户端可以连接到某个db的,所以权限没问题的,同样的问题在以下链接看到了
tp5 mongodb Authentication failed(认证失败)
建议
connector/Mongo.php
135行dsn
增加database
的配置修改前:
修改后
The text was updated successfully, but these errors were encountered: