gpt4 book ai didi

MongoDB 用户未被授权

转载 作者:可可西里 更新时间:2023-11-01 10:49:44 26 4
gpt4 key购买 nike

在 Mongo 中,我创建了一个数据库并专门为该数据库创建了一个用户。当我输入“show users”时,我得到了这个:

    rs0:PRIMARY> show users;
{
"_id" : "sampleuser.sampleuser",
"user" : "sampleuser",
"db" : "sampledb",
"roles" : [
{
"role" : "readWrite",
"db" : "sampledb"
},
{
"role" : "dbAdmin",
"db" : "sampledb"
}


]
}

但是当我尝试使用该用户执行命令时,我得到以下信息:

not authorized on sampledb to execute command { find: "social_posts", filter: { customer_id: "123", 0: { posted: { $ne: 1 } } } }

哪些权限设置错误?

最佳答案

你必须使用 db.auth()在执行任何查询之前对数据库进行身份验证。

来自 db.auth()文档

db.auth()

Allows a user to authenticate to the database from within the shell.

The db.auth() method can accept:

  1. the username and password.

    db.auth( <username>, <password> )
  2. a user document that contains the username and password, and optionally, the authentication mechanism and a digest password flag.

    db.auth( {
    user: <username>,
    pwd: <password>,
    mechanism: <authentication mechanism>,
    digestPassword: <boolean>
    }

Returns: db.auth() returns 0 when authentication is not successful, and 1 when the operation is successful.

关于MongoDB 用户未被授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42845025/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com