Home  >  Blog  >   DevOps

Migration of MongoDB to DynamoDB

Rating: 5
  
 
4034
  1. Share:
DevOps Articles

DynamoDB is one of the non-Structured Query Language (NoSQL) databases that 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 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.

Operations

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

If you want to enrich your career and become a professional in MongoDB, then visit Mindmajix - a global online training platform: "MongoDB TrainingThis course will help you to achieve excellence in this domain. 

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.

Related BLog: [Comparing DynamoDB and MongoDB]

After combining the fields and splitting the tables, we ended up having search results that look 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.

 MindMajix YouTube Channel

You also need to note that in DynamoDB, the 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.

Checkout MongoDB Interview Questions

How to query Dates

Your 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.

Frequently asked Devops Interview Questions

DynamoDB also provides us with the “BatchGetItem” which can be used to get the search results for multiple keywords that 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 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 the development of the product.

Join our newsletter
inbox

Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!

Course Schedule
NameDates
DevOps Training Apr 23 to May 08View Details
DevOps Training Apr 27 to May 12View Details
DevOps Training Apr 30 to May 15View Details
DevOps Training May 04 to May 19View Details
Last updated: 03 Apr 2023
About Author

Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.

read more
Recommended Courses

1 / 15