簡體   English   中英

MongoDB 圖集錯誤:uncaughtException: (Unauthorized) 未授權管理員執行命令

[英]MongoDB atlas error: uncaughtException: (Unauthorized) not authorized on admin to execute command

我是 mongodb 的新手,請原諒我的語言。 我已將應用程序的后端部署到 heroku 並嘗試將其與 Mongodb 連接。 我遵循的步驟如下。

  1. 我在 mongodb.com 上創建了一個項目,添加了一個用戶(角色為atlasAdmin@admin ),添加了 IP。

  2. 我將它連接到 MongoDB Compass 並添加了使用 Compass 所需的數據

  3. 我使用了connect your application並在編輯用戶名、密碼和 dbname 后將下面的字符串保存在 heroku 配置環境變量中。

mongodb+srv://<username>:<password>@vidly.5pn3u.azure.mongodb.net/<dbname>?retryWrites=true&w=majority

但它給出的錯誤是'MongoError: (Unauthorized) not authorized on admin to execute command

我嘗試了以下選項來修復錯誤:

  1. 使用 mongo shell 我嘗試創建用戶。 我使用字符串mongo "mongodb+srv://vidly.5pn3u.azure.mongodb.net/<dbname>" --username <username>連接到 mongo 然后
use admin
db.createUser(
  {
    user: 'admin',
    pwd: 'password',
    roles: [ { role: 'root', db: 'admin' } ]
  }
);
exit;

但它給出了錯誤: uncaught exception: Error: couldn't add user: (Unauthorized) not authorized on admin to execute command

  1. cloud.mongodb.com我將 mongodb 服務器上的角色更改為(dbAdminAnyDatabase@admin、backup@admin、readWriteAnyDatabase@admin、clusterMonitor@admin),但它給出了相同的錯誤。

請建議如何解決此錯誤?

編輯:

我可以使用 mongo connect with the mongo shell訪問數據庫,使用connect with the mongo shell show dbs connect with the mongo shell (但不能創建用戶),並connect using mongodb compass並在 compass 中編輯數據庫。 但是當我嘗試connect your application選項時,它給出了這個錯誤。

添加的用戶具有這些訪問權限(dbAdminAnyDatabase@admin、backup@admin、readWriteAnyDatabase@admin、clusterMonitor@admin),即使該用戶不工作。

您需要安裝最新版本的貓鼬。 例如,您可以使用“yarn add mongoose”來安裝 mongoose。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM