解决 :MongoDB couldn‘t add user: not authorized on ‘your db‘ to execute command

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介: 解决 :MongoDB couldn‘t add user: not authorized on ‘your db‘ to execute command

这个问题主要是mongodb的配置文件开启了授权验证,如果要添加用户可以先暂时关闭。

①将mongod.conf配置文件中的authorization置为disabled

vi /mongodb/single/mongod.conf

②关闭mongodb(直接kill掉进程):

ps -elf|grep mongo
kill -9 199203

③启动mongodb:

/usr/local/mongodb/bin/mongod -f /mongodb/single/mongod.conf

④连接MongoDB客户端:

./mongo --port 27017

⑤新增用户:

use your_db
db.createUser(
    {
    user: "ylw",
    pwd: "123456",
    roles: [{role:"readWrite",db:"your_db"}]
    }
)

⑥停止mongodb

use admin 
db.shutdownServer()

⑦将mongod.conf配置文件中的authorization置为enabled

vi /mongodb/single/mongod.conf

⑧授权的方式启动MongoDB

./mongod --auth -f /mongodb/single/mongod.conf


目录
相关文章
Due to limitations of the com.mongodb.BasicDocument, you can‘t add a second ‘_id‘ criteria. Query al
Due to limitations of the com.mongodb.BasicDocument, you can‘t add a second ‘_id‘ criteria. Query al
358 2
|
NoSQL 关系型数据库 MongoDB
实时计算 Flink版操作报错之使用mongodb cdc时报错Command failed with error 40573,是什么导致的
在使用实时计算Flink版过程中,可能会遇到各种错误,了解这些错误的原因及解决方法对于高效排错至关重要。针对具体问题,查看Flink的日志是关键,它们通常会提供更详细的错误信息和堆栈跟踪,有助于定位问题。此外,Flink社区文档和官方论坛也是寻求帮助的好去处。以下是一些常见的操作报错及其可能的原因与解决策略。
|
NoSQL MongoDB 数据库
MongoDB【部署 03】Windows系统安装mongodb并设置用户名密码(无需安装mongosh)及SpringBoot集成报错 Command failed with error 18
MongoDB【部署 03】Windows系统安装mongodb并设置用户名密码(无需安装mongosh)及SpringBoot集成报错 Command failed with error 18
1801 0
|
NoSQL 关系型数据库 Java
【已解决】Due to limitations of the com.mongodb.BasicDocument, you can‘t add a second ‘$and‘ expression
【已解决】Due to limitations of the com.mongodb.BasicDocument, you can‘t add a second ‘$and‘ expression
880 0
jeeboot集成mongohttps报错‘org.springframework.data.mongodb.core.MongoTemplate‘ in your configuration.
jeeboot集成mongohttps报错‘org.springframework.data.mongodb.core.MongoTemplate‘ in your configuration.
|
NoSQL 数据库 Windows
mongoDB windows reinstall add auth
Mongodb默认启动是不带认证,也没有账号,只要能连接上服务就可以对数据库进行各种操作,这样可不行。现在,我们得一步步开启使用用户和认证。   第一步,我们得定位到mongodb的安装目录。我本机的是C:\mongodb。
758 0

推荐镜像

更多