0

I just installed MongoDB version 4.2.23. I have a TAR.GZ backup that I have extracted. The extracted file has several BSON & JSON files. I am now trying to restore to a database using MongoRestore and the BSON files and am running into an error.

The command I tried is mongorestore -u $admin-p #password -d MongoDB --host=localhost:27017 acknowledgments.bson

After executing that I am getting the following message error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.

Any advice would be appreciated in doing a restore.

Update I have created a user in the database I am attempting to restore. I created a user with the following command: db.create({user: "new_user", pwd: passwordPrompt(), roles: ["readWrite", "dbAdmin"]})

With the new user, I am trying to do the restore as the new user created using the following command: mongorestore -u $new_user_created -d MongoDB --host=localhost:27017 acknowledgments.bson

However I am still receiving the same error.

error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
  • Maybe this one? https://stackoverflow.com/questions/63754742/authentication-failure-while-trying-to-save-to-mongodb/63755470#63755470 – Wernfried Domscheit Nov 06 '22 at 18:47
  • I learned that the database that is being restored needs to have a user on that database. I was trying to do the restore using root credentials. I created a user with the db.CreateUser() command. I am now trying to do a restore using the user I created in the database, but am still getting an error. I will update the OP. Thanks for commenting! – user20186448 Nov 06 '22 at 19:58
  • "I learned that the database that is being restored needs to have a user on that database." Where did you learn this? It is wrong, you just need user with according privileges. And still, you miss the `authenticationDatabase` Apart from that `-d` is deprecated, you should use `--nsInclude` and/or `--nsTo` – Wernfried Domscheit Nov 06 '22 at 20:17
  • The database I am restoring to is completely empty since I just created it. The user I originally used to this restore is an admin user with root privileges but that user is stored in the admin database. Is there something that needs to be done to allow that user access to a different database? – user20186448 Nov 06 '22 at 20:31
  • OMG! `mongorestore -u $admin-p #password -d MongoDB --authenticationDatabase=admin --host=localhost:27017 acknowledgments.bson` If the admin user really has `root` role, (see [Superuser Roles](https://www.mongodb.com/docs/v6.0/reference/built-in-roles/#superuser-roles)) then you don't need anything else. – Wernfried Domscheit Nov 06 '22 at 20:38
  • When you grant `roles: ["readWrite", "dbAdmin"]` then these roles apply to the current database where you create the user. In order to grant them for other databases use `roles: [{ role: "dbAdmin", db: "MongoDB" }]` – Wernfried Domscheit Nov 06 '22 at 20:41

0 Answers0