10

I am trying to restore a MongoDB on an EC2 instance. I am currently running Mongo 4.0. I am restoring a .tgz, which I then unzip, and it contains a directory with all of my files. I previously used this command:

sudo mongorestore --db newDB mongoDump-2018-07-25-0200/viboDB/

Now that I am trying to update our database, I am getting the following error.

building a list of collections to restore from mongoDump-2018-07-25/0200 dir
Failed: viboBI2.Songs: error reading database: command listCollections requires authentication

I have logged into the mongo shell, and used db.auth() to authenticate as an admin. I have tried restarting mongo as well. Any help would be appreciated!

2
  • 1
    Have you tried passing user and password to mongorestore command? Commented Aug 6, 2018 at 19:24
  • 1
    I thought I tried it, but I misspelled my username! That would explain it. For anyone looking at this thread in the future, this worked: sudo mongorestore --db newDB -u user -p password mongoDump-2018-07-25-0200/viboDB/ Commented Aug 6, 2018 at 19:28

1 Answer 1

11

For restoring the Database you need to provide authentication.

mongorestore -u USERNAME -p PASSWORD --authenticationDatabase admin -d dbNAME PATH/TO/DIRECTORY

you can also provide host and port by adding -h and --port

2
  • 1
    Cool, you can use --noIndexRestore to ignore the indexes
    – user7075574
    Commented Oct 22, 2020 at 14:46
  • 1
    --authenticationDatabase admin was so useful. tnx bro.
    – rezshar
    Commented Aug 22, 2021 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.