簡體   English   中英

連接到 MongoDB 時出錯:“管理員未授權執行命令”

[英]Error Connecting to MongoDB: “not authorized on admin to execute command”

我目前正在嘗試將我的應用程序連接到 MongoDB 數據庫(以前在 mlab 上有效)。 我正在使用為連接提供的字符串:

mongodb+srv://admin:password@cluster0.stbko.mongodb.net/name?retryWrites=true&w=majority

當我運行該應用程序時,我收到以下錯誤消息:

(node:35944) UnhandledPromiseRejectionWarning: MongoError: (Unauthorized) not authorized on admin to execute command { insert: "system.indexes", documents: [[{ns admin.sessions} {key [{expires 1}]} {name expires_1} {expireAfterSeconds 0} {unique false}]], ordered: true, writeConcern: { w: "majority" } }

我已經嘗試過 mlab 遷移和上傳數據庫的備份副本,但沒有成功。 我也嘗試更改用戶的權限...我也無法在代碼中找到此錯誤的出處。

我已經查看了多個我不確定它們是否適用於我的帖子: #1#2

我已經使用 mongo shell 連接到數據庫,但是當我嘗試db.getUsers()時出現以下錯誤

2020-12-09T17:17:43.592-0500 E QUERY    [thread1] Error: (Unauthorized) not authorized on admin to execute command { usersInfo: 1.0, $clusterTime: { clusterTime: {1607552228 10}, signature: { hash: {0 [ random numbers here ]}, keyId: more numbers } }, $db: "myDatabase" } :

有什么想法嗎?

沒有 writeMajority 連接怎么樣? 使用連接字符串

mongodb+srv://admin:password@cluster0.stbko.mongodb.net/name

問題在於 mongo-connect 和 connect-mongodb-session 的版本已過時。 升級后我沒有任何問題。

還必須為特定用戶運行db.getUsers() 當我試圖找到我的管理員用戶時,它沒有問題。

暫無
暫無

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

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