Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoError: user is not allowed to do action

I am using MongoDB Atlas as my database.

I am using angular4 with loopback as api.

My application connects to my database fine. However, when I try to get data, I get this error (I have replaced my dbname with dbname):

MongoError: user is not allowed to do action [find] on [dbname.$cmd]

The query works fine if I use a local mongodb client or a mongodb instance on AWS. However, when using atlas, I get this error.

like image 716
Janpan Avatar asked Oct 09 '17 14:10

Janpan


2 Answers

Ugh! This took way too much time to fix! For those of you who have the same issue. I had to do both:

1> I had this error, my problem was that I had not changed the database name from "test" to my own database when coping the connection string. – Meier Dec 8 '17 at 12:43

2>

"mongodb://:@cluster0-shard-00-00- rb899.mongodb.net:27017,cluster0-shard-00-01- rb899.mongodb.net:27017,cluster0-shard-00-02- rb899.mongodb.net:27017/?ssl=true&replicaSet=Cluster0-shard- 0&authSource=admin"

Also, In Atlas, you have to specify the older driver 2.2.12 or later. After doing these things it finally worked.

Thanks all!

like image 81
Michael B Avatar answered Nov 19 '22 19:11

Michael B


In the Atlas cluster, select Security tab, press on button Edit then add a role readWriteAnyDatabase to the user. Try again or refresh your connection to see the result.

like image 17
aviit Avatar answered Nov 19 '22 19:11

aviit