Restore MongoDB locally using MongoRestore - mongodb

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.

Related

Can't do login as root with mongoimport

I want to use mongoimport CLI.
The command succeeds when I use admin database. If the database is something else (whether database exists or not) it fails.
I am using root credentials, but authentication fails.
mongoimport --host=$DB_HOST:$DB_PORT
--username=$DB_ROOT_USERNAME
--password=$DB_ROOT_PASSWORD
--db=$DB_NAME <--- here
--collection=$DB_COLLECION
--file=output.csv
--type=csv
2021-11-14T15:47:14.507+0000 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.
Why can't I use another database than admin ?

Problem connecting to DocumentDB / MongoDB instance on AWS

I set up a new cluster for MongoDB on AWS and switch off the TLS.
I also set it into the VPS of the server from which I'm trying to connect and opened the inbound 27017 port access in the security group of the cluster.
Then when I tried to connect using the AWS-proposed
mongo --host docdb-yyy-mm-dd.cluster-name-of-cluster.us-east-1.docdb.amazonaws.com:27017 --username <myUser> --password <insertYourPassword>
Replacing the myUser and insertYourPassword with the DB credentials, I get the following error:
2021-10-27T15:24:01.548+0000 Error: 301 { ok: 0, errmsg: "Unsupported mechanism", code: 301 } at src/mongo/shell/db.js:1287
exception: login failed
Also, when I try to connect from my local machine via MongoDB compass using
mongodb://<userName>:<insertYourPassword>#docdb-yyy-mm-dd.cluster-name-of-cluster.us-east-1.docdb.amazonaws.com:27017/?replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false
It simply won't connect.
What can I fix to make it work?

Windows Batch Script for Automated Mongodb Backup

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

Can't connect to remote mongodb with macOS

I am trying to connect to a mongodb service hosted on IBM Cloud following this instructions.
When I run the following command
mongo -u $USERNAME -p $PASSWORD --ssl --sslCAFile c5f07836-d94c-11e8-a2e9-62ec2ed68f84 --authenticationDatabase admin --host replset/bdb98a3ac10-0.b8a5e798d2d04f2e860d042c915.databases.appdomain.cloud:30484,bd576-96db98a3ac10-1.b8a5e4e5d042c915.databases.appdomain.cloud:30484
I get this error on macOs, while on Windows 10 the connection is correctly estiblished:
SSL peer certificate validation failed: Certificate trust failure:
Invalid Extended Key Usage for policy; connection rejected
If I connect via MongoDB Compass instead of using the terminal the connection works
I had to add --sslAllowInvalidCertificates flag
https://docs.mongodb.com/manual/reference/configuration-options/#net.ssl.allowConnectionsWithoutCertificates

s3cmd pipe mongodb 3.0.2 SASL auth failed

Does anybody experience an issue with s3cmd and mongoimport after having upgraded to mongodb 3.0.2? I am receiving the SCRAM-SHA1 / SASL error but have no clue how I can fix this? The connection from and to s3 is still unaffected and working properly.
I was untill recently successfully using s3cmd to pipe the output from mongodb 2.6:
s3cmd get s3://filename - | mongoimport -d testdb -c testcollection
which is now returning:
"Failed: error connecting to db server: server returned error on SASL
authentication step: Authentication failed."
Thanks in advance
Try using the --authenticationDatabase parameter to direct the mongoimport tool to the database that holds the user’s credentials. Currently it fails to authenticate since it can't find the location of those credentials.
The full command should look something like this:
s3cmd get s3://filename - | mongoimport -d testdb -c testcollection -u <user_name> -p <password> --authenticationDatabase admin
This is all true to version 2.4 and up of the mongoimport tool, so make sure you have an updated version.