Error: Could not connect to a host in Mongo DB - mongodb

I am trying to import a CSV data file in my MongoDB collection transaction which I created in the Mongo Db Atlas.
I used the following connection string:
'''
'mongoimport --uri "mongodb+srv://username:password#reportingdata-n8b3j.mongodb.net/ecommerce?retryWrites=true&w=majority" --collection transactions --drop --type csv --headerline --file data.csv''
'''
It shows the following error :
'''
2020-06-11T19:28:03.513+0545 WARNING: ignoring unsupported URI parameter 'retrywrites'
2020-06-11T19:28:05.849+0545 error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AtlasError) Authentication failed.
'''
I am currently using mongo db 4.2

Try using this command, worked for me (you can find the command in the command line tools) also check if your IP is whitelisted, add your current IP.
mongoimport --host atlas-1jjmob-shard-0/reportingdata-shard-00-00.66vlq.mongodb.net:27017,reportingdata-shard-00-01.66vlq.mongodb.net:27017,reportingdata-shard-00-02.66vlq.mongodb.net:27017 --ssl --username admin --password <password> --authenticationDatabase admin --db ecommerce --collection transactions --drop --type csv --headerline --file data.csv

Related

Getting unauthorized error during bulk insertions

I am dumping some collections and trying to restore them to cosmosDb
Dumping method
mongodump --host localhost:5960 --db test --collection ‘collectionName’ --gzip --out /mongoBackupFolder/
Restoring method
mongorestore --host blahblah.azure.com --port 9999 -u user -p password --db dummyData --collection dummyData /mongoBackupDB/dummyData/dummyData.bson.gz --gzip --ssl --sslAllowInvalidCertificates
In some collections I have milions of data and sometimes during insertion time i am getting
Error 13 : Insert Error
Error 13 is 13 Unauthorized The request lacks the permissions to complete. Ensure you are using the correct keys.
The error in azure portal
The portal is having issues getting an authentication token. The experience rendered may be degraded.

authenticationDatabase error when running mongoimport

when doing the m103 mongodb course i came across this error when doing the import lab:
user#NHTTPR# mongoimport /dataset/products.json -h localhost:27000 -u m103-application-user -p “m103-application-pass” --authenticationDatabase admin --db applicationData --drop --collection products
2021-04-07T06:19:23.616+0000 error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed) Authentication failed.
the solution was to put single quotes (') around the password. instead of double quotes ( or remove the quotes around the password entirely)
mongoimport /dataset/products.json -h localhost:27000 -u m103-application-user -p 'm103-application-pass' --authenticationDatabase admin --db applicationData --drop --collection products
2021-04-07T06:20:25.025+0000 connected to: mongodb://localhost:27000/
2021-04-07T06:20:25.026+0000 dropping: applicationData.products
2021-04-07T06:20:25.423+0000 9966 document(s) imported successfully. 0 document(s) failed to import.
user#NHTTPR#
use single quote or dont use any quotes following works
mongoimport --username m103-application-user --password m103-application-pass --port=27000 --authenticationDatabase admin --db applicationData --drop --collection products /dataset/products.json

Error when trying to create dump of mongodb database

i tried to create a dump of a mongodb database on remote server which is running centos,nginx,mongodb v4.0.18 using the following command..
mongodump --host localhost:27017 --authenticationDatabase admin --username <uname> --password <password> --db <db> --out <path to dump>
but im getting the following error
Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
I just replaced --host localhost:27017 for --port 27017. My db is in localhost too. I omitted --db <db> --out <path to dump> too. I point to my db with the --authenticationDatabase flag.
I hope this helps.

Mongoexport giving authentication failed error

I am trying to export MongoDB collection.
MongoDB version: 3.0.15 Community
I have tried:
mongoexport --uri "mongodb://<username>:<password>#<host>:<port>/<db_name>?authsource=admin" --collection <collection_name> --out D:/mongo_export/demo.json
This is giving me authentication error as follow:
error connecting to db server: server returned error on SASL authentication step: Authentication failed.
But if I try to go in shell using:
mongo mongodb://<username>:<password>#<host>:<port>/<db_name>?authsource=admin
I am able to go to mongo shell. This means, --uri is correct for mongoexport command.
Then why am I getting error for mongoexport?
As per mongo document for version 3.0, I have tried:
mongoexport -h <host:port>-u <username>-p <password>-d <db name>-c <collection name> -o D:/mongo_export/demo.json
Have you tried to add --jsonArray ?
This worked for me:
mongoexport --uri "mongodb://<username>:<password>#<host>:<port>/<db_name>?authsource=admin" -c <collection_name> -o <path-to-your-export-in-json.json> --jsonArray

Error while importing JSON data from mongo shell to my Atlus cluster

I need to import data from a JSON file to a cluster in Atlas mongodb.
I looked into the documentation and found the following command
mongoimport --host centarosa-shard-0/centarosa-shard-00-00-eplsl.mongodb.net:27017,centarosa-shard-00-01-eplsl.mongodb.net:27017,centarosa-shard-00-02-eplsl.mongodb.net:27017 --ssl --username parvarish --password --authenticationDatabase admin --db --collection --type --file
The error that I am getting is :
Failed: error connecting to db server: no reachable servers
I also tried updating my mongodb version to 4.0.1
But still getting the same error
Please guide me through this.
Thanks
The code provided is missing required arguments. Try the code below, replacing the bolded values with those appropriate for your environment.
mongoimport --host centarosa-shard-0/centarosa-shard-00-00-eplsl.mongodb.net:27017,centarosa-shard-00-01-eplsl.mongodb.net:27017,centarosa-shard-00-02-eplsl.mongodb.net:27017 --ssl --username parvarish --password MYPWD --authenticationDatabase admin --db MYDB --collection MYCOLLECTION --type json --file C:\PATH\IMPORT-FILE.json --jsonArray