【发布时间】:2020-12-14 01:27:55
【问题描述】:
我目前正在尝试将我的应用程序连接到 MongoDB 数据库(以前在 mlab 上工作)。我正在使用为连接提供的字符串:
mongodb+srv://admin:password@cluster0.stbko.mongodb.net/name?retryWrites=true&w=majority
当我运行应用程序时,我收到以下错误消息:
(node:35944) UnhandledPromiseRejectionWarning: MongoError: (Unauthorized) not authorized on admin to execute command { insert: "system.indexes", documents: [[{ns admin.sessions} {key [{expires 1}]} {name expires_1} {expireAfterSeconds 0} {unique false}]], ordered: true, writeConcern: { w: "majority" } }
我已经尝试过 mlab 迁移和上传数据库的备份副本,但没有成功。我也尝试更改用户的权限...我也无法追踪代码中出现此错误的位置。
我已经使用 mongo shell 连接到数据库,但是当我尝试运行 db.getUsers() 时出现以下错误
2020-12-09T17:17:43.592-0500 E QUERY [thread1] Error: (Unauthorized) not authorized on admin to execute command { usersInfo: 1.0, $clusterTime: { clusterTime: {1607552228 10}, signature: { hash: {0 [ random numbers here ]}, keyId: more numbers } }, $db: "myDatabase" } :
有什么想法吗?
【问题讨论】:
-
您尝试使用的用户的权限是什么?您可以在没有身份验证的情况下重新启动 mongodb 以验证用户权限,然后以适当的角色重新启动
-
我已经用 atlasAdmin 和 readWriteAnyDatabase 试过了。我将尝试重新启动 mongodb。当您说重新启动时,您的意思是擦除数据库并从头开始?
-
您能否在 mongodb 上为我澄清一些事情:确切的数据库名称是什么? MongoDB好像是按照Organization --> Projects --> Clusters来组织的……数据库名到底属于哪里?
-
不用清空数据库,在mongo config上,关闭认证重启