In this video.
Let me show you how we can use MongoDB inside Visual Studio code, which means that we can use Visual
Studio code to interact with MongoDB, for example.
We can create, delete updates and fetch a particular record right inside Visual Studio code.
So for this approach, we are not going to install any drivers or create a function to connect to MongoDB.
So this is like using the MongoDB shell.
So in a nutshell, using MongoDB, right inside Visual Studio code is a way to play around with MongoDB.
So let's get started.
Before we continue, I have created a new folder called MongoDB vs Code without any file, and the only
requirement to get started is to make sure that you have the connection string.
And this is where we left in the previous video.
So if we don't have MongoDB connection string, go ahead and create one for yourself.
For this approach, we use what is called the MongoDB drivers, that is Node.js to connect to MongoDB
to interact.
But for this approach we don't need to install any driver.
So it's like using the MongoDB shell.
So the first step is let's go ahead and install the extension called MongoDB such for that and let's
go ahead and install it.
Click on install.
So let me close this tab and you can see that we have MongoDB icon here.
So click on that.
And the first step is we need to connect to MongoDB.
So it says that add connection.
So our click on that and next step is I'm going to click on Connect, but make sure that you have your
connection string being copied so I'll copy it.
And now back to visual CD code and I'm going to click on this code connect and says that paste the connection
string here.
So let me go ahead and paste my connection string and let me hit enter.
All right.
It can see that it has been connected successfully.
So as soon as it connected, let's click on the MongoDB icon and it will say that and the connections
we have all the database inside our dashboard for MongoDB and we have a NOVATEK database and SKU database
and this is what we work on in the previous video.
And by default the extension has given us a default database called MongoDB, which used code playground
DB.
So for this one we can now interact with it for Visual Studio code.
So how are we going to interact with it?
So when we open the school database inside, I have two collections, but for you I believe you're going
to have one.
We have one called student and this is what we worked on from the previous video.
So inside that we have two documents.
The first one represent John and the second one represents Thomas.
So now how can we interact, for example, how we can delete this student or update or create new student?
So let's see how you're going to do it.
So the next step is let's click on Create New Playground.
So let me class this sidebar here and you can see that we have some poor database that we can work with.
So to run this code, click on this icon here.
And when I do that, I'm going to work with the default database given to me by this particular extension.
So we see that running MongoDB playground, let's have some patient.
And now this is what we have from the database given to us by this particular extension.
So how can we also interact with our own database?
So here we go.
The next step is let me close this sidebar here and close this one, and I'm going to save this one.
And let me close all these tabs and let me start from ground root.
So let's go ahead and create a new playground, perfect to see that first tab.
This selected the database that we want to work with and on that we can use any MongoDB method on that.
So let's remove everything from here and let's go ahead and use our own database.
The next step is we need to select our database by making use of use.
So make sure that you have a sample database here.
If you don't have any database, go ahead and click here to create new one.
So right click on your connection string and click on database and name it.
I'll start.
So assuming that you have the database being ready, let's go ahead and select that.
So I'm going to select.
Mine database core school.
Great.
And on that, I have a collection called Students, which is this one.
So by default we have a method called DB database on that.
I want to select my student collection like that.
And on that I have or we have all the method given to us by MongoDB, for example, find as that.
So now it's time to execute this command.
So I click on this icon and let's see the action click.
Yes, and now let's see MongoDB is running and we have it has that how awesome it is.
And for this I can find a particular student by name so I'll provide some query criteria here.
I would say name is equal to Thomas.
Now when I save it, click on that and save the file.
We can name it the way you want it.
So let me go ahead and run this command again.
And indeed I have one student and the same thing.
I can go ahead and create a new student here, so come here, create new student.
DB My collection called Student.
And on that I won't use the method called insect one and I want to create one.
Students pass in object with key value per name.
Let me call this one as Daniel.
And then the city.
Is also say accurate as that.
So let me save it.
And now let me run the file again.
So let's see the results.
You're going to get acknowledged and indeed it has been created.
So if I check my database here, you can see that I'm going to have when I refresh it, I'm going to
have another student.
You can see that now you have three students, so I can go ahead and fetch the student.
So here I can remove the set criteria here, meaning I want to fetch our record.
Let me comment this one.
Save it and let me run it.
This time around, I'm going to sit through a record or document.
I get an error, meaning syntax error here can assign to object of okay, let me save again and let
me run the file again.
Let's see the error.
Nothing.
I think I'm going to get success this time around.
All right.
And indeed, we have three ways to it inside that.
And we can make use of update as we did here.
All right.
So that is how we can play around with MongoDB right inside the Visual Studio code.