1
00:00:13,570 --> 00:00:14,740
In this video.

2
00:00:14,770 --> 00:00:24,190
Let me show you how we can use MongoDB inside Visual Studio code, which means that we can use Visual

3
00:00:24,190 --> 00:00:28,540
Studio code to interact with MongoDB, for example.

4
00:00:28,570 --> 00:00:37,540
We can create, delete updates and fetch a particular record right inside Visual Studio code.

5
00:00:37,690 --> 00:00:45,820
So for this approach, we are not going to install any drivers or create a function to connect to MongoDB.

6
00:00:45,850 --> 00:00:49,480
So this is like using the MongoDB shell.

7
00:00:49,780 --> 00:00:58,570
So in a nutshell, using MongoDB, right inside Visual Studio code is a way to play around with MongoDB.

8
00:00:58,600 --> 00:01:00,250
So let's get started.

9
00:01:00,280 --> 00:01:09,460
Before we continue, I have created a new folder called MongoDB vs Code without any file, and the only

10
00:01:09,460 --> 00:01:14,980
requirement to get started is to make sure that you have the connection string.

11
00:01:14,980 --> 00:01:17,830
And this is where we left in the previous video.

12
00:01:17,830 --> 00:01:23,590
So if we don't have MongoDB connection string, go ahead and create one for yourself.

13
00:01:24,010 --> 00:01:31,600
For this approach, we use what is called the MongoDB drivers, that is Node.js to connect to MongoDB

14
00:01:31,600 --> 00:01:32,620
to interact.

15
00:01:32,620 --> 00:01:36,130
But for this approach we don't need to install any driver.

16
00:01:36,130 --> 00:01:39,310
So it's like using the MongoDB shell.

17
00:01:39,520 --> 00:01:49,030
So the first step is let's go ahead and install the extension called MongoDB such for that and let's

18
00:01:49,030 --> 00:01:50,920
go ahead and install it.

19
00:01:50,920 --> 00:01:52,240
Click on install.

20
00:01:52,420 --> 00:01:57,910
So let me close this tab and you can see that we have MongoDB icon here.

21
00:01:57,910 --> 00:01:59,320
So click on that.

22
00:01:59,320 --> 00:02:03,520
And the first step is we need to connect to MongoDB.

23
00:02:03,550 --> 00:02:05,680
So it says that add connection.

24
00:02:05,680 --> 00:02:12,070
So our click on that and next step is I'm going to click on Connect, but make sure that you have your

25
00:02:12,070 --> 00:02:15,190
connection string being copied so I'll copy it.

26
00:02:15,190 --> 00:02:22,330
And now back to visual CD code and I'm going to click on this code connect and says that paste the connection

27
00:02:22,330 --> 00:02:23,190
string here.

28
00:02:23,230 --> 00:02:27,460
So let me go ahead and paste my connection string and let me hit enter.

29
00:02:28,120 --> 00:02:28,600
All right.

30
00:02:28,600 --> 00:02:32,170
It can see that it has been connected successfully.

31
00:02:32,170 --> 00:02:40,270
So as soon as it connected, let's click on the MongoDB icon and it will say that and the connections

32
00:02:40,270 --> 00:02:49,390
we have all the database inside our dashboard for MongoDB and we have a NOVATEK database and SKU database

33
00:02:49,390 --> 00:02:52,150
and this is what we work on in the previous video.

34
00:02:52,150 --> 00:03:00,070
And by default the extension has given us a default database called MongoDB, which used code playground

35
00:03:00,070 --> 00:03:00,670
DB.

36
00:03:00,790 --> 00:03:06,130
So for this one we can now interact with it for Visual Studio code.

37
00:03:06,130 --> 00:03:08,650
So how are we going to interact with it?

38
00:03:08,650 --> 00:03:15,610
So when we open the school database inside, I have two collections, but for you I believe you're going

39
00:03:15,610 --> 00:03:16,540
to have one.

40
00:03:16,540 --> 00:03:21,220
We have one called student and this is what we worked on from the previous video.

41
00:03:21,310 --> 00:03:25,240
So inside that we have two documents.

42
00:03:25,240 --> 00:03:29,590
The first one represent John and the second one represents Thomas.

43
00:03:29,590 --> 00:03:36,310
So now how can we interact, for example, how we can delete this student or update or create new student?

44
00:03:36,310 --> 00:03:38,290
So let's see how you're going to do it.

45
00:03:38,680 --> 00:03:42,610
So the next step is let's click on Create New Playground.

46
00:03:42,610 --> 00:03:50,980
So let me class this sidebar here and you can see that we have some poor database that we can work with.

47
00:03:51,280 --> 00:03:54,820
So to run this code, click on this icon here.

48
00:03:54,970 --> 00:04:01,480
And when I do that, I'm going to work with the default database given to me by this particular extension.

49
00:04:01,480 --> 00:04:05,620
So we see that running MongoDB playground, let's have some patient.

50
00:04:05,620 --> 00:04:13,660
And now this is what we have from the database given to us by this particular extension.

51
00:04:13,930 --> 00:04:17,950
So how can we also interact with our own database?

52
00:04:17,950 --> 00:04:19,750
So here we go.

53
00:04:20,140 --> 00:04:26,110
The next step is let me close this sidebar here and close this one, and I'm going to save this one.

54
00:04:26,110 --> 00:04:29,890
And let me close all these tabs and let me start from ground root.

55
00:04:30,070 --> 00:04:35,770
So let's go ahead and create a new playground, perfect to see that first tab.

56
00:04:35,770 --> 00:04:42,790
This selected the database that we want to work with and on that we can use any MongoDB method on that.

57
00:04:42,790 --> 00:04:47,740
So let's remove everything from here and let's go ahead and use our own database.

58
00:04:47,740 --> 00:04:52,930
The next step is we need to select our database by making use of use.

59
00:04:52,930 --> 00:04:56,380
So make sure that you have a sample database here.

60
00:04:56,410 --> 00:05:00,760
If you don't have any database, go ahead and click here to create new one.

61
00:05:00,760 --> 00:05:06,070
So right click on your connection string and click on database and name it.

62
00:05:06,070 --> 00:05:06,880
I'll start.

63
00:05:06,910 --> 00:05:12,370
So assuming that you have the database being ready, let's go ahead and select that.

64
00:05:12,370 --> 00:05:13,060
So I'm going to select.

65
00:05:13,430 --> 00:05:15,800
Mine database core school.

66
00:05:17,750 --> 00:05:18,510
Great.

67
00:05:18,530 --> 00:05:23,930
And on that, I have a collection called Students, which is this one.

68
00:05:23,930 --> 00:05:30,140
So by default we have a method called DB database on that.

69
00:05:30,140 --> 00:05:34,820
I want to select my student collection like that.

70
00:05:34,820 --> 00:05:43,460
And on that I have or we have all the method given to us by MongoDB, for example, find as that.

71
00:05:43,460 --> 00:05:45,950
So now it's time to execute this command.

72
00:05:45,950 --> 00:05:50,450
So I click on this icon and let's see the action click.

73
00:05:50,450 --> 00:05:59,540
Yes, and now let's see MongoDB is running and we have it has that how awesome it is.

74
00:05:59,540 --> 00:06:07,070
And for this I can find a particular student by name so I'll provide some query criteria here.

75
00:06:07,070 --> 00:06:11,150
I would say name is equal to Thomas.

76
00:06:11,600 --> 00:06:16,100
Now when I save it, click on that and save the file.

77
00:06:16,100 --> 00:06:18,050
We can name it the way you want it.

78
00:06:18,050 --> 00:06:20,960
So let me go ahead and run this command again.

79
00:06:20,960 --> 00:06:25,220
And indeed I have one student and the same thing.

80
00:06:25,220 --> 00:06:31,940
I can go ahead and create a new student here, so come here, create new student.

81
00:06:32,630 --> 00:06:35,690
DB My collection called Student.

82
00:06:36,710 --> 00:06:42,860
And on that I won't use the method called insect one and I want to create one.

83
00:06:42,860 --> 00:06:47,000
Students pass in object with key value per name.

84
00:06:47,030 --> 00:06:49,700
Let me call this one as Daniel.

85
00:06:50,090 --> 00:06:52,460
And then the city.

86
00:06:53,400 --> 00:06:58,500
Is also say accurate as that.

87
00:06:58,500 --> 00:06:59,790
So let me save it.

88
00:06:59,790 --> 00:07:02,000
And now let me run the file again.

89
00:07:02,010 --> 00:07:03,740
So let's see the results.

90
00:07:03,750 --> 00:07:08,340
You're going to get acknowledged and indeed it has been created.

91
00:07:08,340 --> 00:07:14,040
So if I check my database here, you can see that I'm going to have when I refresh it, I'm going to

92
00:07:14,040 --> 00:07:15,240
have another student.

93
00:07:15,240 --> 00:07:20,370
You can see that now you have three students, so I can go ahead and fetch the student.

94
00:07:20,370 --> 00:07:25,080
So here I can remove the set criteria here, meaning I want to fetch our record.

95
00:07:25,170 --> 00:07:26,430
Let me comment this one.

96
00:07:26,430 --> 00:07:28,050
Save it and let me run it.

97
00:07:28,290 --> 00:07:31,620
This time around, I'm going to sit through a record or document.

98
00:07:31,620 --> 00:07:41,910
I get an error, meaning syntax error here can assign to object of okay, let me save again and let

99
00:07:41,910 --> 00:07:43,410
me run the file again.

100
00:07:43,410 --> 00:07:45,000
Let's see the error.

101
00:07:45,480 --> 00:07:46,110
Nothing.

102
00:07:46,110 --> 00:07:48,540
I think I'm going to get success this time around.

103
00:07:49,440 --> 00:07:50,100
All right.

104
00:07:50,100 --> 00:07:53,610
And indeed, we have three ways to it inside that.

105
00:07:53,610 --> 00:07:57,120
And we can make use of update as we did here.

106
00:07:57,540 --> 00:07:57,960
All right.

107
00:07:57,960 --> 00:08:03,240
So that is how we can play around with MongoDB right inside the Visual Studio code.

