Mongodb Atlas: not authorized on admin to execute

2019-06-16 04:44发布

I have a MongoDB Atlas cluster within which I am trying to simply copy a database within the same instance. Unfortunately, every time I try to run db.copyDatabase() or copydb admin command, I get the following error:

not authorized on admin to execute command

Which is very strange, because I just have one user, and it has access to everything, at least as far as I can tell on atlas (Click to see image here).

I did some search in stackoverflow, but it looked like most of the answers pertain to mongod instances running locally, and not ones running in atlas... Did I setup the user wrong?

5条回答
戒情不戒烟
2楼-- · 2019-06-16 05:16

this error is because you are trying create the colecction above admin, in atlas this isn't possible because securty.

in this case you need to use the word key use [collection_name]

this is the link for this answer.

it is in spanish.

https://victorroblesweb.es/2016/12/24/crear-una-base-datos-mongodb/

查看更多
霸刀☆藐视天下
3楼-- · 2019-06-16 05:18

I had the same issue when I was trying to connect to a cluster with Node.js version 3.0 or later and using the link below:

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

By selecting version 2.2.12 or later and using the link provided, everything went well

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

查看更多
smile是对你的礼貌
4楼-- · 2019-06-16 05:26

I had faced a similar obstacle and spent hours, the problem was with the connection string provided by mongodb atlas which is: mongodb+srv://username:password@clusterName-jynkd.mongodb.net/test?retryWrites=true

I used a different connection string and worked perfectly. This is it: mongodb://username:password@clusterName+port/yourdb?retryWrites=true&ssl=true&authSource=admin. Make sure the clustername + port are like this: clusterName-shard-00-00-jynkd.mongodb.net:27017

查看更多
地球回转人心会变
5楼-- · 2019-06-16 05:37

I ended up asking this question to MongoDB University discussion board. In case anyone comes across this, this is apparently because I am using a free cluster.

查看更多
手持菜刀,她持情操
6楼-- · 2019-06-16 05:39

In case you have been using mongoose, I solved a similar error updating mongoose to latest version (based on this post).

查看更多
登录 后发表回答