Mongodb Atlas: not authorized on admin to execute command

狂风中的少年 提交于 2019-12-04 00:41:10

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.

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

This drove me insane... Turns out the standard link provided by MongoDB was trying to name my default database "admin". Change link from

mongodb+srv://username:password@portfoliosite-ezeot.mongodb.net/admin?retryWrites=true&w=majority

to

mongodb+srv://username:password@portfoliosite-ezeot.mongodb.net/test?retryWrites=true&w=majority

You can put any word in for test just not admin. Hope this helps!

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

just use this version and then copy its link and replace the username and password from your mongodb atlas that have the permision to read and write and it will connect i was also having the same problem spent a lot of time to solve this then i tries 2.2.12 version and it workerd.

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/

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!