A few days ago, I took control of a project that was written in Node & mySQL. Since the project would involve a lot of high end queries and more complex Database structure, I thought it would be best to take this battle to my comfort zone - MongoDB.
I decided to migrate from mySQL to MongoDB. I had never done this before, and I wasn't even sure if it could actually happen on a large scale.
1. I would build an endpoint that would execute a mySQL DB Query pulling everything from a table.
(Ex. 'SELECT * FROM table_name)
2. I would then make the server save everything into a JSON file using the node module fs. This concludes the endpoint.
3. With some configurations, I will have all the tables from the MySQL Database seperately in JSON formats.
4. Now, I can use the JSON content as POST Requests made to the newly built MongoDB Database.
I was about to go ahead with this solution, but I just thought of exploring how the rest of the world does this. Turned out, there were already tools for this thing.
Enter Studio3T, a powerful IDE for MongoDB. They had a specific feature just for this purpose! In just a few minutes, all the SQL database was transferred to my local MongoDB!
I decided to migrate from mySQL to MongoDB. I had never done this before, and I wasn't even sure if it could actually happen on a large scale.
Solution 1
The first possible solution was to do this manually using the server as a mediator.1. I would build an endpoint that would execute a mySQL DB Query pulling everything from a table.
(Ex. 'SELECT * FROM table_name)
2. I would then make the server save everything into a JSON file using the node module fs. This concludes the endpoint.
3. With some configurations, I will have all the tables from the MySQL Database seperately in JSON formats.
4. Now, I can use the JSON content as POST Requests made to the newly built MongoDB Database.
I was about to go ahead with this solution, but I just thought of exploring how the rest of the world does this. Turned out, there were already tools for this thing.
Solution 2: Studio3T
Enter Studio3T, a powerful IDE for MongoDB. They had a specific feature just for this purpose! In just a few minutes, all the SQL database was transferred to my local MongoDB!
This might not look like a big deal, but believe me when I say this, it took a lot of energy to persuade my lazy mind to read the documentation of a tool, when I already had a solution in mind.
When you go through Studio 3T, you find that it really has a ton of new and amazing features! For example, it has a Visual Query Builder, which actually lets us build queries without having to know the MongoDB syntax! Isn't that amazing?!
Visual Query Builder |
From a learner's point of view, learning the core syntax can be held at a higher precedence, but if you're just going to ignore treading a path that is a shortcut, how can you really call yourself a lazy programmer? In other serious words, how can you justify that you can build a project with a proper balance of speed and quality?
As programmers, we're always looking to take pride in coding our way through everything. Yes, we're known for finding the easiest way out of everything, but sometimes the easiest ways are already built in the form of applications, rather than modules or libraries. If you refuse to use them, it might take a lot of time for you to build something what is already built, and it will definitely take years to build something that significantly helps the world.
Comments
Post a Comment