Mongodb Atlas:在admin上没有被授权执行命令的权限

24

我有一个MongoDB Atlas集群,我试图在同一实例中复制一个数据库。不幸的是,每次我尝试运行db.copyDatabase()或copydb管理员命令时,我都会收到以下错误:

not authorized on admin to execute command

这非常奇怪,因为我只有一个用户,并且它可以访问所有内容,至少在atlas上我可以确定:

在此输入图片描述

我在stackoverflow上搜索了一些信息,但似乎大部分答案都适用于在本地运行的mongod实例,而不是在atlas上运行的实例...难道我的用户设置有问题吗?

13个回答

24

我最终在MongoDB大学讨论版上提出了这个问题。以防有人遇到同样的情况,这似乎是因为我使用的是免费的集群。


6
供您(以及其他遇到此问题的人)参考:https://docs.atlas.mongodb.com/unsupported-commands/ 和 https://docs.atlas.mongodb.com/reference/free-shared-limitations/。 - Pete Garafano
2
我有同样的问题,但是将M10更改为M10是否解决了这个问题? - Alan Ortega
以下是我最满意的答案:https://dev59.com/Bxf8s4cB2Jgan1znEuSf - Huiyang Shan

22

当我尝试使用以下链接连接到一个Node.js版本3.0或更高的集群时,遇到了相同的问题:

mongodb+srv://username:password@cluster0-eoowo.mongodb.net/test?retryWrites=true

通过选择版本2.2.12或更高并使用提供的链接,一切都进行得很顺利。

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


16

这让我疯了...原来MongoDB提供的标准链接试图将我的默认数据库命名为“admin”。请更改以下链接:

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

你可以测试任何单词,但不能使用“admin”。希望这可以帮到你!


谢谢,帮了我大忙了。 - Gilberto Galea
非常感谢!这正是我的问题所在!一旦我将我的Node.js驱动程序设置为2.2.12或更高版本,我就在进程中取得了进展,但仍然出现“Error: querySrv EREFUSED”错误。将"admin"更改为任何其他字面意思都可以解决该错误。 - Earle Poole

6
只需使用此版本,然后复制其链接并替换您的MongoDB Atlas中具有读写权限的用户名和密码,它将连接。我也遇到了同样的问题,花了很多时间来解决,然后我尝试了2.2.12版本,它可以正常工作。 enter image description here

3

导致此错误的另一个原因是登录的用户与启动有问题操作的用户不同--要使用db.killOp,您需要以与启动该操作的用户相同的身份登录到mongo shell中。

在Atlas上,数据库用户可以使用db.killOp()命令来终止自己的操作。您是正确的,拥有atlasAdmin权限的帐户无法终止由其他账户在集群上启动的操作。

如果您在mongo shell中使用应用程序用于启动有问题操作的用户进行身份验证,然后您就可以使用db.killOp()来终止该操作。

(来源为Atlas支持票据)


3

我曾经面临过类似的障碍并花费了数小时,问题出在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


0

0
如果您一直在使用mongoose,我解决了一个类似的错误,将mongoose更新到最新版本(基于此帖子)。

0
在我的情况下,我在尝试连接到mongodb atlas时遇到了这个问题。我通过从mongdb uri字符串中删除以下内容来解决了这个错误:ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true 原始链接:mongodb+srv://username:password@hostname/dbname?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true 纠正后:mongodb+srv://username:password@hostname/dbname

0

这个答案并不完全针对原始问题,但是这是我在谷歌搜索我的错误信息“mongodb atlas errmsg: '(unauthorized) not authorized on admin to execute command”时一直看到的主要帖子。

如果你在2021年遇到了这个错误,并且正在使用Mongoose V4或更低版本连接MongoDB Atlas,请尝试将Mongoose更新到最新版本(发布此答案时为V5.12.13)。

打开终端,导航到您的项目目录,并运行

npm i mongoose@latest    

我之前一直在使用一门关于Node.js和Express的在线课程提供的起始代码,该代码是在2018年中期制作的。这个起始代码使用了Mongoose V4,而且对我来说非常有效。我的MongoDB Atlas集群是M0免费版。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接