Skip to content

egg-mongoose 普通库dbowner权限,连接的时候报错not authorized on xxx to execute command { serverStatus: 1 } #550

@nalantianyi

Description

@nalantianyi

@huacnlee
egg团队你们好,环境信息如下
mongodb版本2.6
账户权限dbOwner
连接url mongodb://xxx:xxx@yyyy/xx
使用egg-mongoose连接报错not authorized on xxx to execute command { serverStatus: 1 }

使用原生mongodb驱动或者mongoose均正常

连接日志:先显示连接成功,后执行失败
egg-agent.log中:
2017-03-10 22:38:28,417 INFO 98529 [egg-mongoose] mongodb://xxx:xxx@yyyy/xx connected successfully
common-error.log中:
2017-03-10 22:38:28,453 ERROR 98529 nodejs.MongoError: not authorized on veleco to execute command { serverStatus: 1 }

查阅egg-mongoose代码发现如下代码
app.beforeStart(function* () {
app.coreLogger.info('[egg-mongoose] starting...');
yield heartEvent.await('connected');
/* const serverStatus = yield db.db.command({
serverStatus: 1,
});
assert(serverStatus.ok === 1, '[egg-mongoose] server status is not ok, please check mongodb service!');
*/
app.coreLogger.info('[egg-mongoose] start successfully and server status is ok');
注释掉命令serverStatus: 1后能正常连接和操作
账户权限dbOwner时失败,改成admin后成功!!所以猜测dbowner用户并没有db.serverStatus()权限,望egg查阅下,因为对这块东西不是特别熟悉,如果是我配置数据库等问题导致的,还望指点

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions