Import Metadata and indexes

Migration Module (2.3.3) - Migrate from MongoDB to Amazon DocumentDB using Database Migration Service (DMS)

From your AWS loud9 environment, you will now create indexes that are not created by AWS Database Migration Service (DMS).

Download Amazon DocumentDB tools from git with the following commands.

bash

curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo /usr/local/bin/pip install pymongo
sudo yum install git -y
git clone https://github.com/awslabs/amazon-documentdb-tools.git
ls -l

installation

Go to EC2 Console to pick private IP address.

privateip

Export the metadata from source mongoDB running in EC2 instance to the dump directory using Amazon DocumentDB Migration Tool.

bash

export PATH=$PATH:/usr/local/bin/
sudo /usr/local/bin/pip install bson
mkdir dump

Substitute the private IP of your instance in the host information.

bash

sudo python amazon-documentdb-tools/index-tool/migrationtools/documentdb_index_tool.py --host **<your EC2 instance private ip>** --port 27017 --username dmsuser --password 202xDoc --auth-db admin --dir dump --dump-indexes

bash

sudo rm -rf dump/config
ls -lrt dump/labdb/

dumpindexes

Run the following command against the target Amazon DocumentDB cluster to show any compatibility issues we may have with indexes before importing to Amazon DocumentDB. Substitute username and password of your Amazon DocumentDB cluster in the below command.

bash

sudo python amazon-documentdb-tools/index-tool/migrationtools/documentdb_index_tool.py --show-issues --dir dump --host <your-cluster-DNS>:27017  --tls --tls-ca-file rds-combined-ca-bundle.pem --username <username> --password <password>

indexresult

You have now identified that a “2dsphere” index is not support yet by Amazon DocumentDB.

You will now import the indexes that are compatible, using the “–skip-incompatible” argument.

bash

sudo rm -rf dump/config
sudo python amazon-documentdb-tools/index-tool/migrationtools/documentdb_index_tool.py --restore-indexes --dir dump --host <your-cluster-DNS>:27017  --tls --tls-ca-file rds-combined-ca-bundle.pem --username <username> --password <password> --skip-incompatible

imported

Validate the indexes created in Amazon DocumentDB .

Log in your Amazon DocumentDB endpoint and run the following queries.

bash

mongo --ssl --host <cluster endpoint>:27017 --sslCAFile rds-combined-ca-bundle.pem --username <username> --password <insertYourPassword>

MongoDB shell

use labdb
db.locations.getIndexes()
db.customers.getIndexes()

indexes

You have successfully created metadata and the supported indexes.