Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
735 views
in Technique[技术] by (71.8m points)

mongodb - 如何使用带有用户名和密码的mongorestore / mongodump?(How to use mongorestore/mongodump with username and password?)

I know this is a basic security measure, but I can't make it works with my mongodb installation.

(我知道这是一项基本的安全措施,但是我无法使其与mongodb安装一起使用。)

Each time I run the command :

(每次我运行命令:)

mongorestore dump_folder -u "username" -p "password"

It returns:

(它返回:)

error reading database: not authorized on DATABASE_NAME to execute command { listCollections: 1, cursor: { batchSize: 0 } }

My question is : What is the permission that I need to enable and how ?

(我的问题是:我需要启用什么权限以及如何启用?)

For the time being, I just turn off the Mongo's security in /etc/mongod.conf and start it back after I restore/dump my databases.

(暂时,我只是在/etc/mongod.conf关闭Mongo的安全性, /etc/mongod.conf在还原/转储数据库后重新启动它。)

Additional Note: This is how I prepared my databases and its user

(附加说明:这是我准备数据库及其用户的方式)

  1. I log in with my admin account, create a database, named DATABASE001

    (我使用管理员帐户登录,创建一个名为DATABASE001的数据库)

  2. And create a user:

    (并创建一个用户:)

     use DATABASE001 db.createUser({ user: "USER001", pwd: "mypassword", roles:[ { role: "readWrite", db: "DATABASE001" },"dbAdmin" ] }) 

For roles, I add readWrite to DATABASE001 and also dbAdmin I want this user (USER001) be able to backup or restore his database (DATABASE001).

(对于角色,我将readWrite添加到DATABASE001,还将dbAdmin添加到我希望该用户(USER001)能够备份或还原其数据库(DATABASE001)。)

  1. I tested it by login with this command.

    (我通过使用此命令登录进行了测试。)

    It successfully logged in

    (它成功登录)

     mongo localhost -u USER001 -p mypassword --authenticationDatabase DATABASE001 
  2. I want to dump this database content with:

    (我想通过以下方式转储该数据库内容:)

     mongodump -u USER001 -p mypassword --authenticationDatabase DATABASE001 

    it throws me an error: Failed: error getting database names: not authorized on admin to execute command { listDatabases: 1 }

    (它引发了一个错误: Failed: error getting database names: not authorized on admin to execute command { listDatabases: 1 })

What is this listDatabases ?

(这个listDatabases是什么?)

how can I add it to my roles?

(如何将其添加到我的角色中?)

  ask by DennyHiu translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
$ mongorestore --username adminUser --password pass123 --authenticationDatabase admin --db exampleDB dump/exampleDB

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...