如何在启用授权的情况下备份 mongodb 数据库?

How to backup a mongodb database with authorization enabled?

我是 运行 Digital Ocean 上的一个 mongo 数据库。我已使用以下教程进行设置:Mongodb setup and secured it with this tutorial: MongoDb security

现在我正在尝试创建特定数据库的转储。我正在使用本文中所述的以下命令:Backup & Restore Mongodb:

sudo mongodump --db dbName --out /var/backups/mongobackups/日期 +"%m-%d-%y"``

但是,我收到以下错误消息:

Failed: error getting collections for database 'dbName': error running 'listCollections'. Database: 'dbName' Err: command listCollections requires authentication.

我已经用 root 用户登录了我的服务器。我错过了什么?

由于错误清楚地表明“命令 listCollections 需要身份验证”。您应该尝试“使用用户名和密码转储数据库 mongodump -u=USERNAME -p=PASSWORD --db=DB_NAME”。

:)