Search code examples
amazon-web-servicesamazon-ec2aws-documentdb

Unable to run mongoexport on AWS EC2 instance


I have data in a DocumentDB database that I would like to export to an S3 bucket. However, when I try to run the mongoexport command:

mongoexport --uri="my_cluster_address/database_to_use" --collection=my_collection --out=some_file.json

I get this error:

could not connect to server: server selection error: server selection timeout, current topology: 
{ Type: Single, Servers: [{ Addr: docdb_cluster_address, Type: Unknown, State: Connected, Average RTT: 0, Last error: 
connection() : connection(docdb_cluster_address[-13]) incomplete read of message header: read tcp port_numbers-
>port_numbers: i/o timeout }, ] }

I am able to ssh into the cluster and do all sorts of transformations and really anything else related to database work but when I exit the mongoshell and try to run the mongoexport command it does not work. I already downloaded the mongoexport tools to the EC2 instance and added them to the .bash_profile path. I do not think it is a networking issue because if that were the case I wouldn't be able to ssh into the cluster so I think I am good on that part, I am not sure what I could be missing here. Any ideas?


Solution

  • When working with DocumentDB the mongoexport does not take the same parameters as it normally would when exporting/importing/restoring/dumping from/to MongoDB

    Below is the command that worked for me and a link to the documentation: https://docs.aws.amazon.com/documentdb/latest/developerguide/backup_restore-dump_restore_import_export_data.html

    mongoexport --ssl \
        --host="tutorialCluster.node.us-east-1.docdb.amazonaws.com:27017" \
        --collection=restaurants \
        --db=business \
        --out=restaurant2.json \
        --username=<yourUsername> \
        --password=<yourPassword> \
        --sslCAFile rds-combined-ca-bundle.pem
    

    And below is the documentation for how it would normally work if you were working with MongoDB: https://docs.mongodb.com/database-tools/mongoexport/