尝试连接时 MongoDB Shell 身份验证失败

问题描述 投票:0回答:0

我按照本教程 https://www.digitalocean.com/community/tutorials/how-to-configure-remote-access-for-mongodb-on-ubuntu-20-04 来配置 MongoDB。我正在使用 MongoDB Shell。

  • 我可以使用
    mongo admin -u user -p password
    命令进行身份验证
  • 或者使用
    mongo
    >
    use admin
    >
    db.auth("user","password");
    (它让我感到
    1
    ,所以我假设身份验证有效)。
  • 但不是
    mongo
    >
    db.auth("user","password");
    并且不知道为什么。
  • mongo "mongodb://server-ip:27017"
    命令也有效。
  • mongo "mongodb://user@server-ip:27017"
    询问密码,当我输入时,验证失败(密码正确)。
  • 我可以使用具有以下 URI
    mongodb://server-ip:27017
    mongodb://user:password@server-ip:27017
    的 Studio 3T 进行连接。但是当我尝试访问一个文件时,它抛出了这个错误
Mongo Server error (MongoCommandException): Command failed with error 13 (Unauthorized): 'not authorized on local to execute command { collStats: "startup_log", scale: 1.0, $db: "local", lsid: { id: UUID("26de2f21-85a3-4ede-a027-e5619bae6ee0") } }' on server server-ip:27017. 

The full response is:
{
    "ok" : 0.0,
    "errmsg" : "not authorized on local to execute command { collStats: \"startup_log\", scale: 1.0, $db: \"local\", lsid: { id: UUID(\"26de2f21-85a3-4ede-a027-e5619bae6ee0\") } }",
    "code" : 13.0,
    "codeName" : "Unauthorized"
}

我做错了什么?我需要一个 URI 来将我的数据库连接到我在 DigitalOcean 上的 Nodejs 应用

database mongodb ubuntu digital-ocean mongo-shell
© www.soinside.com 2019 - 2024. All rights reserved.