Hi everyone!
My cluster already created and in this video I will show you how to connect the NestJS with the MongoDB
database.
And now let's go to the techniques and go to the Mongo.
And to be honest instead of showing. Instead of
Remember this the code and show that to you.
I will NOT do that.
Okay, I will show you the documentation.
Because in the real life, if you work with the real company, you might work with different frameworks
and different languages and with different frameworks.
It has a many way to connect the database.
So for that reason.
Never remember the code, instead of remember the documentation.
Okay, understand the documentation and read the docs and copy paste into your project.
So for that reason I will show you the documentation and copy that.
Okay.
I will not remember this code right here and show you.
Now let me copy.
Let me explain what's in the Mongo module.
Actually the Mongo module right here already.
Write
It already write by the mongoose package.
Right here.
NestJS right here.
Okay.
And it's already export.
So for that reason, we must import the Mongo module inside my module being the app module.ts
The reason we import it inside the app.module.ts because I was many module.
Many child module will accept inside the Mongo, right?
For that reason we will import Mongo module right here.
Let me copy that.
Open the app module.
Open the import and paste it right here.
And I will copy the import statement okay.
And paste that.
And with the forRoot right here we must replace with my database in the previous video okay.
Go to the database and go to the cluster and click the connect, okay.
It will show the list of pop up right here.
And click on the driver right here, and choose Node.js.
And inside here we have a URL, right?
Let me copy that.
Copy that and replace with the Mongo URL right here.
Now you can see, this is my Mongodb.
And in the db underscore password we will remove that and replace with the password of the database.
In the previous video right.
We already set up the database account.
And that is let me see, okay.
Now let me run the application to see if it works or not.
npm run start
:dev
And wait a bit.
Now, right now, the authentication already failed, I think, because.
Because I already was wrong.
The password.
I think like this.
Let me see.
Oh.
I don't know why.
Let me reset the password.
Go to the security and database access.
I will edit the password.
Okay I will.
Let me click on.
Right here.
I will click on update passwords and let me try to change that.
And let me close project and run this again.
Now you can see.
For that reason the application already successfully right here.
Okay.
If you see the Nestjs application started, it means we already connected the database successfully.
So make sure you remember the password okay.
If not you can always go to the database access and click on this and press on the edit password over
here to generate the new password.
Okay I will close the video right now and see you in the next one.