MongoError: user is not allowed to do actions

I am using MongoDB Atlas as my database.

I am using angular4 with loopback as api.

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

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

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

+11
source share
4 answers

I had the same error.

  • If you are using the MongoDB NodeJS driver v.3.0, refer to the MikaS post for the MongoClient.connect changes that need to be made. fooobar.com/questions/420195 / ...

  • Atlas MongoDB, 3.4, .

    mongodb://<USERNAME>:<PASSWORD>@cluster0-shard-00-00-
    rb899.mongodb.net:27017,cluster0-shard-00-01-
    rb899.mongodb.net:27017,cluster0-shard-00-02-
    rb899.mongodb.net:27017/<DBNAME>?ssl=true&replicaSet=Cluster0-shard-
    0&authSource=admin
    
+8

Atlas Security, Edit, readWriteAnyDatabase . , .

+3

v3.0 mongodb Node.js, API , MongoDB Atlas URI 3.4 :

MongoClient.connect(uri, function(err, client) {
  console.log("Connected successfully to server");

  const db = client.db(dbName);
});
+1

! , ! , . :

1> , , "test" . - , 8 17 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 & amp;; = administrator authorization source "

In addition, in Atlas you must specify an older driver 2.2.12 or newer. After that, everything finally worked.

Thanks everyone!

+1
source

Source: https://habr.com/ru/post/1687153/


All Articles