0

I have setup a superuser in mongodb and I am able to do a backup manually in the command line or connect to the database with the username and password in the console or in Compass, but if I move that command to a batch script and run the script, I always get the error:

Failed: can't create session: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed) Authentication failed.

The command is:

mongodump --username myusername --password mypassword --out C:\backups --db mydb --authenticationDatabase admin

I have updated the bindIp to 0.0.0.0 and added security: authorization: "enabled".

Any thoughts on why I can't run this in the batch script. I am using Mongo 4.2

Thanks

Eddy
  • 145
  • 14
  • 1
    I'm unfamiliar with MongoDB, however their support [references](https://docs.mongodb.com/manual/reference/program/mongodump/#mongodump-options) show options such as `--db` using the format `--db=mydb` where as your example above uses `--db mydb`. – Durry42 Mar 03 '20 at 05:46
  • Check your username and password for characters that Windows treats specially in a batch file. Compare with the connection logged by mongod to make sure it's what you expect. – Joe Mar 03 '20 at 09:24
  • 1
    If your password contains symbols such as `< > ^ % & | "` they maybe causing issues when used in the Batch File. Try running your Batch File again but enable echo (`@echo on`) and include a `pause` on last line to keep it open after execution so you can see any possible issues. – Durry42 Mar 03 '20 at 09:26
  • Yeah it was the special character in the password. Thanks for the tip. – Eddy Mar 03 '20 at 14:28

0 Answers0