I wish to export a collection from a remote mongo database.
Locally, i connect to my remote mongo database via the following mongo command:
mongo mongodb://<shard-01>,<shard-02>,<shard-03>?replicaSet=shard-0 -ssl --authenticationDatabase admin --username admin --password password
By running the command above, i can basically connect to the remote database and run queries there.
Now, i wish to do a mongoexport for this database for a specific collection. But it seems i cannot figure out the correct syntax to do it.
I tried
mongoexport mongodb://<shard-01>,<shard-02>,<shard-03>?replicaSet=shard-0 -ssl --authenticationDatabase admin --username admin --password password --collection car --out ./car.json
mongoexport --uri=mongodb://admin:password@<shard-01>,<shard-02>,<shard-03>?replicaSet=shard-0 --collection car --out ./car.json
mongoexport --uri=mongodb://<shard-01>,<shard-02>,<shard-03>?replicaSet=shard-0 --username admin --password password --collection car --out ./car.json
But none of those seems to be working. It all complains that
error connecting to db server: no reachable servers
mongoexport documentation states that you can't specify some options when using uri:
IMPORTANT
The following mongoexport options are incompatible with the --uri option. Instead, specify these options as part of your --uri connection string when applicable:
--host
--port
--db
--username
--password (when specifying the password as part of the URI connection string)
--authenticationDatabase
--authenticationMechanism
So you will need provide a URI based on this scheme:
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
An example would be:
mongoexport --uri "mongodb://username:[email protected]:27017,test-shard-00-01-1qpma.mongodb.net:27017,test-shard-00-02-1qpma.mongodb.net:27017/collection?replicaSet=test-shard-0&ssl=true&authSource=admin" --collection collectionName --out collectionName-dump.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With