我按照本教程 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"
询问密码,当我输入时,验证失败(密码正确)。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 应用