Mongodb Atlas:管理员未授权执行命令
Mongodb Atlas: not authorized on admin to execute command
我有一个 MongoDB Atlas 集群,我试图在其中简单地复制同一个实例中的数据库。不幸的是,每次我尝试 运行 db.copyDatabase() 或 copydb 管理命令时,我都会收到以下错误:
not authorized on admin to execute command
这很奇怪,因为我只有一个用户,它可以访问所有内容,至少据我在 atlas 上所知:
我在 Whosebug 中进行了一些搜索,但看起来大多数答案都与本地的 mongod 实例 运行ning 有关,而不是 atlas 中的 运行ning... 我是否设置了用户错了吗?
我最后向 MongoDB 大学讨论区提出了这个问题。如果有人遇到这个问题,这显然是因为我使用的是免费集群。
此错误是因为您正在尝试在 admin 之上创建集合,在 atlas 中这是不可能的,因为安全。
在这种情况下,您需要使用关键字 use [collection_name]
这是此答案的link。
它是西班牙语。
https://victorroblesweb.es/2016/12/24/crear-una-base-datos-mongodb/
当我尝试连接到 Node.js 版本 3.0 或更高版本 的集群并使用下面的 link 时,我遇到了同样的问题:
mongodb+srv://username:password@cluster0-eoowo.mongodb.net/test?retryWrites=true
通过选择版本 2.2.12 或更高版本 并使用提供的 link,一切顺利
mongodb://username:password@cluster0-shard-00-00-eoowo.mongodb.net:27017,cluster0-shard-00-01-eoowo.mongodb.net:27017,cluster0-shard-00-02-eoowo.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true
我遇到过类似的障碍并花了几个小时,问题出在 mongodb atlas 提供的连接字符串上,它是:mongodb+srv://username:password@clusterName-jynkd.mongodb.net/test?retryWrites=true
我使用了不同的连接字符串并且运行良好。就是这个:
mongodb://username:password@clusterName+port/yourdb?retryWrites=true&ssl=true&authSource=admin
。
确保 clustername + port 是这样的:
clusterName-shard-00-00-jynkd.mongodb.net:27017
如果你一直在使用 mongoose,我解决了将 mongoose 更新到最新版本的类似错误(基于此 post)。
只需使用此版本,然后复制其 link 并替换具有读写权限的 mongodb atlas 中的用户名和密码,它将连接 我也有相同的问题花了很多时间来解决这个问题然后我尝试了 2.2.12 版本并且它有效。
这让我抓狂...原来 MongoDB 提供的标准 link 试图命名我的默认数据库 "admin"。将 link 从
更改为
mongodb+srv://username:password@portfoliosite-ezeot.mongodb.net/**admin**?retryWrites=true&w=majority
至
mongodb+srv://username:password@portfoliosite-ezeot.mongodb.net/**test**?retryWrites=true&w=majority
您可以输入任何单词进行测试,但不能输入管理员。希望这对您有所帮助!
导致此错误的另一个原因是以不同于启动错误操作的用户身份登录 -- 要使用 db.killOp
,您需要登录 mongo shell 与启动操作的用户相同。
On Atlas, database users can utilize the db.killOp()
command to kill their own operations. You are correct that an account with atlasAdmin privileges cannot kill operations on the cluster that were not initiated by that account.
If you authenticate in the mongo shell with the user that the application used to initiate the offending operations, you should then be able to use db.killOp() to kill said operations.
(来源是 atlas 支持票)
在我的例子中,我在尝试连接到 mongodb 时遇到了这个问题 atlas.I 通过从 mongdb uri 字符串中删除这些来删除错误。 ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true
原始 link : mongodb+srv://username:password@hostname/dbname?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true
整改后:mongodb+srv://用户名:密码@hostname/dbname
这个答案不是 100% 特定于 OG 问题,但是,这是主要的 post 我在谷歌搜索我的错误消息“mongodb atlas errmsg: '(unauthorized ) 未授权管理员执行命令
如果您在 2021 年遇到此错误并且使用 Mongoose V4 或更低版本连接 MongoDB Atlas,请尝试将 Mongoose 更新到最新版本([=23= 时 V5.12.13 ]正在回答这个问题)。
打开您的终端,导航到您的项目目录,然后运行
npm i mongoose@latest
我一直在使用 2018 年年中制作的关于 Node.js 和 Express 的在线课程的入门代码。起始代码一直在使用 Mongoose V4,这个解决方案对我很有效。我的 MongoDB Atlas 集群是 M0 免费套餐。
我已经更改了节点版本 2.2.12 或更高版本
我也遇到了一些问题,这个 post 的答案组合帮助了我,谢谢。 :) 我试图从一个旧项目中播种,所以我将 mongoose 升级到最新版本,删除了已弃用的 {useMongoClient: true}
选项,然后使用 mongodb atlas 给我的连接字符串(字符串以 mongodb:// 开头,选项 'use node 2.12 or higher')。我还有其他一些与连接有关的问题,但这是我在数据库配置中列入白名单的 IP 的问题。将 0.0.0.0/0 列入白名单以进行任何访问以检查这是问题所在。
我有一个 MongoDB Atlas 集群,我试图在其中简单地复制同一个实例中的数据库。不幸的是,每次我尝试 运行 db.copyDatabase() 或 copydb 管理命令时,我都会收到以下错误:
not authorized on admin to execute command
这很奇怪,因为我只有一个用户,它可以访问所有内容,至少据我在 atlas 上所知:
我在 Whosebug 中进行了一些搜索,但看起来大多数答案都与本地的 mongod 实例 运行ning 有关,而不是 atlas 中的 运行ning... 我是否设置了用户错了吗?
我最后向 MongoDB 大学讨论区提出了这个问题。如果有人遇到这个问题,这显然是因为我使用的是免费集群。
此错误是因为您正在尝试在 admin 之上创建集合,在 atlas 中这是不可能的,因为安全。
在这种情况下,您需要使用关键字 use [collection_name]
这是此答案的link。
它是西班牙语。
https://victorroblesweb.es/2016/12/24/crear-una-base-datos-mongodb/
当我尝试连接到 Node.js 版本 3.0 或更高版本 的集群并使用下面的 link 时,我遇到了同样的问题:
mongodb+srv://username:password@cluster0-eoowo.mongodb.net/test?retryWrites=true
通过选择版本 2.2.12 或更高版本 并使用提供的 link,一切顺利
mongodb://username:password@cluster0-shard-00-00-eoowo.mongodb.net:27017,cluster0-shard-00-01-eoowo.mongodb.net:27017,cluster0-shard-00-02-eoowo.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true
我遇到过类似的障碍并花了几个小时,问题出在 mongodb atlas 提供的连接字符串上,它是:mongodb+srv://username:password@clusterName-jynkd.mongodb.net/test?retryWrites=true
我使用了不同的连接字符串并且运行良好。就是这个:
mongodb://username:password@clusterName+port/yourdb?retryWrites=true&ssl=true&authSource=admin
。
确保 clustername + port 是这样的:
clusterName-shard-00-00-jynkd.mongodb.net:27017
如果你一直在使用 mongoose,我解决了将 mongoose 更新到最新版本的类似错误(基于此 post)。
只需使用此版本,然后复制其 link 并替换具有读写权限的 mongodb atlas 中的用户名和密码,它将连接 我也有相同的问题花了很多时间来解决这个问题然后我尝试了 2.2.12 版本并且它有效。
这让我抓狂...原来 MongoDB 提供的标准 link 试图命名我的默认数据库 "admin"。将 link 从
更改为mongodb+srv://username:password@portfoliosite-ezeot.mongodb.net/**admin**?retryWrites=true&w=majority
至
mongodb+srv://username:password@portfoliosite-ezeot.mongodb.net/**test**?retryWrites=true&w=majority
您可以输入任何单词进行测试,但不能输入管理员。希望这对您有所帮助!
导致此错误的另一个原因是以不同于启动错误操作的用户身份登录 -- 要使用 db.killOp
,您需要登录 mongo shell 与启动操作的用户相同。
On Atlas, database users can utilize the
db.killOp()
command to kill their own operations. You are correct that an account with atlasAdmin privileges cannot kill operations on the cluster that were not initiated by that account.If you authenticate in the mongo shell with the user that the application used to initiate the offending operations, you should then be able to use db.killOp() to kill said operations.
(来源是 atlas 支持票)
在我的例子中,我在尝试连接到 mongodb 时遇到了这个问题 atlas.I 通过从 mongdb uri 字符串中删除这些来删除错误。 ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true
原始 link : mongodb+srv://username:password@hostname/dbname?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true
整改后:mongodb+srv://用户名:密码@hostname/dbname
这个答案不是 100% 特定于 OG 问题,但是,这是主要的 post 我在谷歌搜索我的错误消息“mongodb atlas errmsg: '(unauthorized ) 未授权管理员执行命令
如果您在 2021 年遇到此错误并且使用 Mongoose V4 或更低版本连接 MongoDB Atlas,请尝试将 Mongoose 更新到最新版本([=23= 时 V5.12.13 ]正在回答这个问题)。
打开您的终端,导航到您的项目目录,然后运行
npm i mongoose@latest
我一直在使用 2018 年年中制作的关于 Node.js 和 Express 的在线课程的入门代码。起始代码一直在使用 Mongoose V4,这个解决方案对我很有效。我的 MongoDB Atlas 集群是 M0 免费套餐。
我已经更改了节点版本 2.2.12 或更高版本
我也遇到了一些问题,这个 post 的答案组合帮助了我,谢谢。 :) 我试图从一个旧项目中播种,所以我将 mongoose 升级到最新版本,删除了已弃用的 {useMongoClient: true}
选项,然后使用 mongodb atlas 给我的连接字符串(字符串以 mongodb:// 开头,选项 'use node 2.12 or higher')。我还有其他一些与连接有关的问题,但这是我在数据库配置中列入白名单的 IP 的问题。将 0.0.0.0/0 列入白名单以进行任何访问以检查这是问题所在。