MongoError: user is not allowed to do action

前端 未结 6 498
[愿得一人]
[愿得一人] 2021-02-05 10:29

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,

相关标签:
6条回答
  • 2021-02-05 10:30

    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!

    0 讨论(0)
  • 2021-02-05 10:39

    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.

    0 讨论(0)
  • 2021-02-05 10:39

    https://docs.mlab.com/troubleshooting-atlas-connection-issues/#getlog-error

    For anyone get the user is not allowed to do action [getLog] on [admin.] error. Had to explicitly give the user the clusterMonitor role

    0 讨论(0)
  • 2021-02-05 10:40

    I had the same error myself.

    • If you are using v.3.0 of the MongoDB NodeJS driver refer to MikaS post for the MongoClient.connect changes that need to be made. https://stackoverflow.com/a/47662979/8775223

    • To connect your application to Atlas MongoDB use the 3.4 driver eg.

      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
      
    0 讨论(0)
  • 2021-02-05 10:42

    Make sure to whitelist the IP you are using to connect from the Mongo CLI to your DB. Do this under the project Network Access tab.

    0 讨论(0)
  • 2021-02-05 10:52

    If you are using v3.0 mongodb for Node.js you should use the new API as follows, and the MongoDB Atlas URI connection string for driver 3.4 and earlier:

    MongoClient.connect(uri, function(err, client) {
      console.log("Connected successfully to server");
    
      const db = client.db(dbName);
    });
    
    0 讨论(0)
提交回复
热议问题