1
00:00:02,090 --> 00:00:08,710
So what is mongoose? Mongoose is an ODM, an object document mapping library

2
00:00:08,810 --> 00:00:15,580
and that's really similar to sequelize which was an ORM, an object relational mapping library

3
00:00:15,680 --> 00:00:20,320
and the difference of course just is that mongodb is not a relational database,

4
00:00:20,450 --> 00:00:22,310
it's a document database,

5
00:00:22,310 --> 00:00:26,130
it thinks in documents and hence we have an ODM here.

6
00:00:26,480 --> 00:00:31,840
So the idea stays the same though, we have some data, some entity in our application,

7
00:00:31,850 --> 00:00:38,570
let's say a user and we want to save that to a collection, we want to map our javascript object to a

8
00:00:38,570 --> 00:00:41,940
document in a collection that could look something like this

9
00:00:42,020 --> 00:00:45,200
and of course we can write the query for that on our own,

10
00:00:45,200 --> 00:00:52,130
that is exactly what we did in the last module but it would be a bit easier if we could just focus on

11
00:00:52,160 --> 00:00:57,590
our objects, on our data and see how it should look like and then work with it and this is not even

12
00:00:57,590 --> 00:00:59,450
the final syntax you see here,

13
00:00:59,450 --> 00:01:05,500
we can use mongoose a bit differently than you see it here but even that would be a bit more concise.

14
00:01:05,570 --> 00:01:07,040
So just as sequelize,

15
00:01:07,250 --> 00:01:13,010
mongoose tries to allow us to define models with which we then work and where all the queries are done

16
00:01:13,010 --> 00:01:18,180
behind the scenes which of course does not mean that we can't influence and that we can't change some

17
00:01:18,180 --> 00:01:19,160
things.

18
00:01:19,340 --> 00:01:25,400
The core concepts are that we work with schemas and models where we define how our data should look like

19
00:01:25,580 --> 00:01:29,450
and then we have so-called instances where we instantiate our models,

20
00:01:29,480 --> 00:01:34,800
so where we create real javascript objects we can work with that are based on our blueprints

21
00:01:35,270 --> 00:01:43,130
and once we get that setup, we can run queries and there we again use our objects, we use our models

22
00:01:43,370 --> 00:01:45,430
and we can then query the database

23
00:01:45,470 --> 00:01:52,000
but through mongoose with various helpers we get, some syntactical sugar and so on.

24
00:01:52,010 --> 00:01:57,680
So that's the idea behind mongoose, really similar to what sequelize did for SQL

25
00:01:57,800 --> 00:02:02,800
and therefore with that, let's dive in, let's add it to our project and let's see how we can use it there.
