Mindmajix

Migration of MongoDB to DynamoDB

DynamoDB is one of the non-Structured Query Language (NoSQL) databases which are currently in use today. Scaling of this database is very easy, and it offers no overhead in terms of administration. However, it has a limitation when it comes to the design of the schema. Once you have migrated your data from MongoDB to DynamoDB, you will notice that the task of administering the data will be reduced, and that it will be possible for you to archive the old data. The archiving here can mean that the data which is not queried more often by the database can be moved and stored in a slow storage. Each of the components can have a single table. After setting up the tables, the read and write operations can be specified for each of the tables, and this will be determined by how often the table is being accessed.

Screenshot_35

The database reserves up to 300 seconds of unused read and write capacity.

However, the index is one of the limitations that DynamoDB has. You are allowed to use either a hash key, or a combination of the hash key and the range key. This means that a multiple-key index is not supported. The following is an example of the search result entry in our system:

{
name : “john”,
sex : “male”,
country : “US”,
results : “…”,
added_on : 2015-07-03T11:00:00Z
}

The solution to the limitation is to combine fields, and then split out the tables. When the tables are split, then this means that we will be having more tables in our system, and this will help in improving our control over capacity planning for the different data which we are handling. After combining the fields and splitting the tables, we ended up having search results which looks as follows:

{
name : “john”,
sex : “male”,
results : “…”,
created_on : 2015-07-03T11:00:00Z
}

{
name : “hellen”,
sex : “female”,
results : “…”,
created_on : 2015-08-04T12:00:00Z
}

However, you need to be careful when dealing with this, as it has to match your use case and even the product. This means that it might not be an obvious solution to all of the similar problems, but it has guided you on how you can think outside the box and get things done.

You also need to note that in DynamoDB, native Date or Date Time object is not supported. This means that you have to come up with ways on how to handle these. The solution to this is to convert this into the Linux timestamp, and then store the number. An example of this is given below:

{
name : “john”,
sex : “male”,
results : “…”,
added_on : 1248764145
}

What happens is that the conversion of the date into timestamp is done at the application layer, and before we can query the DynamoDB. The sorting can also be performed at this point.

How to query Dates

You application can need to query the database for data, include the field for the date. In this case, you will have to Query the database rather than using the “GetItem” command. An example of this is given below:

find({
“keyword” : “john”,
“added_date” : new Date(2015, 1, 2)
});

In DynamoDB, I might need to query the following command:

 

“name” : {
“AttributeValueList” : [ { “S” : “john” } ],
“ComparisonOperator” : “EQ”
},
“added_date” : {
“AttributeValueList” : [
{ “N” : 1520170510 },
{ “N” : 1620256897 }
],
“ComparisonOperator” : “BETWEEN”
}

The querying can be done, but there are some problems associated with it. First, the Query command is slower when compared to the “GetItem” command, which is straight forward. In the latter case, the user is given both the hash key and the range key for matching.

DynamoDB also provides us with the “BatchGetItem” which can be used to get the search results for multiple keywords which are frequently used in applications. Each of the API requests to the DynamoDB can lead to an overhead which can add up whenever we are handling the names the application is requesting.

Storing Data as String

One can choose to store their data which has been formatted as a string. Consider the example given below:

{
name : “john”,
sex : “male”,
country : “US”,
results : “…”,
created_on : “2015-02-04”
}

We can then use the “GetItem” object so as to get our data more quickly. This is shown in the example given below:

“name” : {
“S” : “john”,
},
“added_date” : {
“S” : “2015-02-04”),
}

With the above, we will be in a position to fetch the data in batches. When you use the DynamoDB web console, the data will also become human-readable, which means that the user will save some time.

Now that you using DynamoDB, you will notice how it offers an effortless scaling and zero maintenance. Some creativity is needed when designing the tables and breaking out of the old paradigm. Other than concentrating on configuring your MongoDB, your efforts will only be needed in development of the product.

0 Responses on Migration of MongoDB to DynamoDB"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.
Course Adviser

Fill your details, course adviser will reach you.