Mongoexport giving authentication failed error - mongodb

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

Related

Mongorestore from localhost to cosmosDb fails with "disable retryable writes by specifying "retrywrites=false"

mongo client v 4.4
mongorestore --host <host> --port 10255 -u <user> -p <password> --db <db_name> --collection structures structures.bson --ssl --sslAllowInvalidCertificates
2020-10-03T23:13:44.440+0300 Failed: <db_name>.structures: error restoring from structures.bson: (BadValue) Retryable writes are not supported. Please disable retryable writes by specifying "retrywrites=false" in the connection string or an equivalent driver specific config.
I tried the other way
mongorestore "mongodb://<host>:<password>#<name>:10255/?ssl=true&retrywrites=false&appName=#name#" dump/
with the same error.
I found that this command --writeConcern="{w:0}" can solve the "rewrite=false" error. I have tried it and here's my command.
mongorestore.exe --uri "<cosmosdb_connect_string>" --db Database1 --collection collection1 --ssl --sslAllowInvalidCertificates edx-dump/Database1/collection1.bson --writeConcern {w:0}

Error: Could not connect to a host in Mongo DB

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

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

Unable to restore MongoDB from db_dump

I am trying to restore MongoDB from db_dump via terminal.
$ mongorestore -h localhost:27017 --db aaaa_production --archive=db_dump_071118.gz --gzip
Error parsing command line: unrecognised option '--archive=db_dump_071118.gz'
try 'mongorestore --help' for more information
Before running mongorestore command make sure that MongoDB is running on the same port as specified in mongorestore command. In your case, MongoDB should be running on localhost:27017.Then run following command to restore database:
$ mongorestore -h localhost:27017 --db aaaa_production --gzip --archive=db_dump_071118.gz

Problems with importing existing mongodb to Atlas

Just finished setting up my mongodb and found out that there is a free service called Atlas. Started up a cluster and ran a mongodump and mongorestore as explained here https://www.mongodb.com/blog/post/atlas-on-day-one-importing-data, but can't seem to get it to work.
Here is my shell commands:
mongorestore --ssl --db=infovis --host infovis-shard-00-00-nmctc.mongodb.net:27017,infovis-shard-00-01-nmctc.mongodb.net:27017,infovis-shard-00-02-nmctc.mongodb.net:27017/test?replicaSet=Infovis-shard-0" --authenticationDatabase admin --dir=dump/infovis --username danielbook --password <Password>
What am I doing wrong?
EDIT: Solved the problem by running mongoimport on the server instead.
So, I solved this by using mongoimport instead. I had just created the database in mongo, so I could just use the same csv files and then use
mongoimport -h cluster0-shard-00-00-nmctc.mongodb.net:27017 -d infovis -c flights -u <USER> -p <PASSWORD> --file march_2016.csv --type csv --headerline
for each file I want to import to the Atlas database.