This technical tutorial demonstrates how to transition a project from MongoDB to MySQL using TypeORM. The process includes updating Docker Compose configurations, setting environment variables, establishing connections via MySQL Workbench, and refactoring NestJS database modules to integrate TypeORM entities.
Length 9:03
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #typeorm #mysql #docker #nestjs #database #programming #backend #coding #tutorial #software
0:00 All right, so let's look at how we can implement 0:02 TypeORM into 0:04 our application and use it as our database of choice 0:08 instead of MongoDB. 0:10 Now, since we have an abstract repository in 0:12 our application, it's gonna be a 0:14 lot easier to switch out which database we're using since all of 0:18 our repositories in our microservices are extending this common one 0:22 in our lib's 0:24 database folder. This abstract repository can be changed 0:28 to work with TypeORM. 0:30 We'll, of course, have to update our existing schemas 0:34 and define 0:34 them in a language that TypeORM understands. 0:37 So let's go ahead and get started. Now, a quick note, I'm gonna be 0:41 keeping all of this code related to moving over to TypeORM 0:45 inside of a new GitHub branch called TypeORM. 0:49 So if you wanna see the completed code with all of the 0:53 TypeORM integration completed, you can run Git Checkout 0:57 TypeORM to get on this branch. I'm gonna be 1:01 working off of the main branch for this series of lectures. 1:05 The first place we're gonna start is our Docker Compose file, where right 1:09 now for our database, you can see we're running Mongo using the 1:13 Mongo image. I wanna swap this out for MySQL 1:17 instead. So to do this, I'll change Mongo 1:20 to MySQL, and for the image, we're gonna use 1:24 the official MySQL image, 1:28 and then we're gonna specify an env file that the MySQL 1:32 image will use to read in credentials for our database. 1:36 So let's go ahead and specify this env file. 1:38 We'll create a new .env at the root of our project where we will 1:42 have environment variables specific to just these extra images like 1:46 MySQL. So let's go ahead and create this .env. 1:50 Now, lastly, the database will be listening on port 1:53 three three oh 1:54 six by default for incoming connections.
The rest of the transcript is for members.
Sign in