1
00:00:00,360 --> 00:00:00,690
All right.

2
00:00:01,110 --> 00:00:07,230
And once we're familiar with mangoes, let's get up a notch and finally start using our database on

3
00:00:07,230 --> 00:00:07,830
our server.

4
00:00:08,430 --> 00:00:14,640
And the first thing we need to do is to set up a connection and at least a basic setup is going to look

5
00:00:14,640 --> 00:00:18,510
something like this where we're going to import mangoes.

6
00:00:18,630 --> 00:00:20,250
And of course, we're going to do that.

7
00:00:20,610 --> 00:00:21,380
Ian Connect.

8
00:00:21,390 --> 00:00:21,780
Yes.

9
00:00:22,170 --> 00:00:27,600
So I'm looking for any beef older and then more specifically for connect dress, I'm not here at the

10
00:00:27,600 --> 00:00:29,610
top above the connection string.

11
00:00:29,970 --> 00:00:31,560
We're going to go with Konst Mangoes.

12
00:00:32,009 --> 00:00:35,910
That's the name of my instance and the sequel to require.

13
00:00:36,180 --> 00:00:41,400
And of course, I'm looking for the marquis and wants to have the instance of the method.

14
00:00:41,400 --> 00:00:43,110
Name is Connect.

15
00:00:43,380 --> 00:00:49,800
So we go here with Mangoes Dot Connect, and the first thing we want to pass in is the connection string

16
00:00:49,980 --> 00:00:50,310
party.

17
00:00:50,310 --> 00:00:53,430
If you remember, I said that we'll have to make some changes.

18
00:00:53,820 --> 00:00:54,300
Take a look.

19
00:00:54,630 --> 00:00:58,340
So this is going to be my username, correct?

20
00:00:58,830 --> 00:01:00,720
But then what is the value for the password?

21
00:01:01,350 --> 00:01:02,790
Well, that is some dummy value.

22
00:01:03,120 --> 00:01:06,450
So in here, we need to pass in our actual password.

23
00:01:06,810 --> 00:01:10,380
So in my case, of course, that is one two three four.

24
00:01:10,800 --> 00:01:17,160
But I strongly suggest using more secure one for your application online here.

25
00:01:17,160 --> 00:01:20,250
At the very end, we have my first database.

26
00:01:20,910 --> 00:01:25,560
So this is what they set up by default and now is going to be the name for the database.

27
00:01:25,890 --> 00:01:27,030
If I don't change it.

28
00:01:27,540 --> 00:01:29,740
And you're probably wondering, well, wait a minute.

29
00:01:30,150 --> 00:01:32,760
I mean, we didn't set this up on the Atlas.

30
00:01:33,060 --> 00:01:37,440
So why it's here it, if it's not going to be there, it's going to be created for you.

31
00:01:38,190 --> 00:01:41,850
So here you have two options, either you can just go with this one.

32
00:01:42,120 --> 00:01:44,670
Or in my case, I'm going to remove it.

33
00:01:45,000 --> 00:01:48,840
And again, just make sure that you don't remove more than you should.

34
00:01:49,170 --> 00:01:54,710
So you want to remove everything, starting with the fourth flash all the way to the question mark.

35
00:01:55,080 --> 00:01:57,180
And here, of course, you need to come up with a name.

36
00:01:57,420 --> 00:02:02,190
And in my case, I'm going to go with the same name as my application.

37
00:02:02,760 --> 00:02:09,570
So since I have zero point one for no tutorial and then task manager is zero point three, that's exactly

38
00:02:09,570 --> 00:02:10,949
what I'm going to set up over here.

39
00:02:11,340 --> 00:02:17,160
So I'm going to go with zero point three then hyphen, and I think I'm going to go uppercase, so I'm

40
00:02:17,160 --> 00:02:21,360
going to go with zero point three task and manager.

41
00:02:21,630 --> 00:02:26,910
Again, this is going to be the database name, and if you haven't created that database already, they

42
00:02:26,910 --> 00:02:28,320
will create for you.

43
00:02:28,710 --> 00:02:32,190
And once we add these changes, our connection string is ready to go.

44
00:02:32,490 --> 00:02:36,210
So now we're simply need to pass in as a first argument.

45
00:02:36,690 --> 00:02:42,540
Now the second argument is going to be options, and effectively this is we're all passing some values

46
00:02:42,750 --> 00:02:47,160
just to avoid some deprecation warnings and you'll see what I'm talking about in a second.

47
00:02:47,550 --> 00:02:52,320
But for the time being, we'll just leave it empty and then this returns a promise.

48
00:02:52,350 --> 00:02:54,300
So we're simply going to go with that then.

49
00:02:54,630 --> 00:03:00,240
And since I want to see whether I'm successful as far as the connection, I'll just pass in a callback

50
00:03:00,240 --> 00:03:02,280
function and I'll say log.

51
00:03:02,580 --> 00:03:11,660
And of course, I will remove the semicolon and I'll say connected connected to the DB about that.

52
00:03:11,970 --> 00:03:16,020
And then since there might be an error as well, we also want to go with catch.

53
00:03:16,410 --> 00:03:18,690
And of course, we'll just be looking for error.

54
00:03:18,990 --> 00:03:24,240
So we have our callback function and I'll say error and simpler console.log there.

55
00:03:24,870 --> 00:03:28,800
I'll say here console.log and I'm going to be looking for error.

56
00:03:29,100 --> 00:03:34,980
And once we say nothing happens and the reason why nothing happens is because we're not executing this

57
00:03:34,980 --> 00:03:35,490
function yet.

58
00:03:36,090 --> 00:03:43,020
But if you remember during tutorial, one of the first things that are covered is the fact that if we

59
00:03:43,020 --> 00:03:52,560
have a function in a module where the function is effectively executed there and then we only need to

60
00:03:52,770 --> 00:03:58,230
import meaning require the module and we'll right away execute the function.

61
00:03:58,650 --> 00:04:05,670
So I simply want and I go to objets and this is just temporary because we will change the set up around

62
00:04:06,120 --> 00:04:06,630
this one.

63
00:04:06,810 --> 00:04:08,010
We won't leave it this way.

64
00:04:08,460 --> 00:04:11,100
I just want to get the connection up and running.

65
00:04:11,490 --> 00:04:15,870
And therefore, I'm just going to go to objets and then we go with the require.

66
00:04:15,900 --> 00:04:22,050
I notice I'm not assigning any kind of variable simply go with require that and we look in the DB.

67
00:04:22,410 --> 00:04:25,350
And then more specifically, we're looking for a connect.

68
00:04:25,830 --> 00:04:33,210
And once you say you have tons of deprecation warnings, and don't worry, we'll fix them in a second,

69
00:04:33,540 --> 00:04:35,250
but all the way on the bottom.

70
00:04:35,580 --> 00:04:42,360
If everything is correct or we're here, if you pass in the correct password and you grab the correct

71
00:04:42,360 --> 00:04:46,620
connection string, then you should see connected to the database.

72
00:04:47,430 --> 00:04:52,350
And if I want to test out the error, I'll simply remove the four, since I know that that is going

73
00:04:52,350 --> 00:04:53,700
to be a wrong password.

74
00:04:54,150 --> 00:04:58,020
So once I save now, of course, I'll have this error.

75
00:04:58,320 --> 00:04:59,190
So I'm just going to keep on.

76
00:04:59,410 --> 00:05:02,380
All in a notice here, it's kind of, say, Atlus era.

77
00:05:02,830 --> 00:05:04,260
And of course, Harry, you know why?

78
00:05:04,270 --> 00:05:06,880
Because my password is correct.

79
00:05:07,300 --> 00:05:13,630
And if we'll take a look at our graphical interface and atlas, once we refresh, we're not going to

80
00:05:13,630 --> 00:05:17,740
see any changes because again, we haven't set up any kind of logic.

81
00:05:18,070 --> 00:05:20,840
So you're looking at it, you're like, OK, I still have one database.

82
00:05:20,870 --> 00:05:21,460
What's happening?

83
00:05:21,880 --> 00:05:22,450
Don't worry.

84
00:05:22,780 --> 00:05:29,650
Once we start adding items, that database will be created for us, in my case, zero point three task

85
00:05:29,650 --> 00:05:30,160
manager.

86
00:05:30,520 --> 00:05:36,280
And even though I will refactor this in the next video because there are some gotchas that I want to

87
00:05:36,280 --> 00:05:42,520
talk about before we do that, I'll show you how we can remove those deprecation warnings in a console.

88
00:05:42,820 --> 00:05:47,410
And if you remember, we just need to pass in a second argument, which is going to be an object.

89
00:05:47,620 --> 00:05:54,550
And here we just need to pass a following key value pairs and we'll start with use new you are all parser

90
00:05:54,940 --> 00:05:56,590
and start equal to true.

91
00:05:56,990 --> 00:06:05,560
I don't look for use create index so that one equal to true and then we'll go and use, find and modify

92
00:06:05,920 --> 00:06:07,300
that one will be false.

93
00:06:07,600 --> 00:06:14,620
And then lastly, we want to go and use unified topology, and not one will set equal to true.

94
00:06:14,950 --> 00:06:18,400
So once I save now, I don't have any of those warnings.

95
00:06:18,730 --> 00:06:22,330
I simply see servers listening on Port 3000.

96
00:06:22,630 --> 00:06:24,790
And then I have connected to the database.

97
00:06:25,120 --> 00:06:30,550
And if that is also something that you see in a console, you are in good shape and we're ready to move

98
00:06:30,550 --> 00:06:31,690
on to the next step.

