So to get started,
attached to find a project snapshot,
which is the same project
we used in the MySQL course sections,
but without all the MySQL logic.
It's just a little starting state,
which we are going to enhance
throughout this course section.
So you'll find this project attached.
You can download, and unZIP it,
move it somewhere on your hard drive
where you wanna work on it.
And then as a first step,
you should open this terminal here in Visual Studio Code.
And run NPM install to install all the dependencies
I listed in package.JSON, the ExpressJS package for example
so that this project is able to work correctly.
Once you did that, you can run NPM start
to start this development server.
So this Node server powered by Nodemon
for automatic reloading as you learn.
And once this is running, you keep this up and running.
And you can then, of course, visit this in the browser.
It starts on port 3000.
So if you enter local host 3000,
you should see a page like this.
Now, I'm zoomed in quite a bit here.
If you zoom out, it's smaller.
And I will say right away
that I got some basic styling here,
but it's not optimized for mobile or anything like that
because I really wanna focus on the database part here.
So we got this All Posts page
without any posts at this point of time.
And we got a Create Post for creating new posts.
But at the moment, this page also doesn't work.
We're going to add the logic to make it work
throughout this course section.
And therefore, let's now see how we should proceed here.
Now, it would be nice to view all posts.
But for that to work, we need to be able to create posts.
Now, for this to work on the other hand,
we need to make sure that this dropdown here
for selecting an author works.
At the moment, it doesn't work because at the moment,
we have no data source
for fetching a list of predefined authors.
And whilst we could, of course,
also have a hard code this in our code here,
I actually wanna use a database collection
that stores the author data,
which we then query from inside our code
to then pre-populate this rendered template here.
And to be precise, the dropdown in this template.
Hence, we need a MongoDB database
with an authors collection,
where we as an administrator already add some authors,
which we can then use here.
And for all of that, of course, we have to make sure
that we got a running MongoDB database server.
Now, on Windows, it should be running as a service already.
If not, make sure you start this service again
as you learn in the previous course section.
On macOS, if it is still running,
you don't need to do anything.
If it's not running yet,
you need to re-execute this mongod command with dbpath
and log path as you learn it in the last section.
So if you're not sure how to start your servers,
definitely go through these setup lectures
in the previous section again so that you do
have a running MongoDB server on your system.
Once you've got this MongoDB server up and running,
make sure it stays up and running
as long as you're working with it.
And then we can use the Mongo Shell to connect
to this server.
So that's what I'll do here.
I now established a connection like this.
And now, of course, we can first of all, show our DBs.
And here, I see my rating portal
on which I worked in the last course section,
but nothing besides that.
And for this course section,
we're going to add a new database.
Now, you learn that with MongoDB,
adding a new database simply means that you start using it.
And then as soon as you insert data,
all the collections and databases you are working with
will be created automatically if they don't exist yet.
So here, I'll start using a special database
with the use command.
And I wanna use the blog database.
The name is up to you,
but since we are working on a blog in this course section,
this should be a quite fitting name.
So I'll use blog here.
Now, with that here,
we can start inserting some data already.
And as I mentioned a couple of minutes ago,
I wanna insert some author data
so that we can use that for creating our posts.
Hence, here, we can refer to the database
we are currently working with, with the DB keyword.
And then use dot to access a collection on that database.
And here, I'll access the authors collection.
Though this collection name, of course,
is always up to you because as you learn,
it will be created on the fly if it doesn't exist yet.
And then we learn in the last course section
that we can simply insert a new document
with the insertOne command.
And then passing the document
with curly braces to insertOne.
Now, as laid out a couple of minutes ago,
an author should have a unique ID, a name,
and an email address.
Now, the ID will be generated automatically.
So therefore, we only need to add a name
and an email address to that author document.
And hence, it will be a rather simple,
straightforward document here.
I will just add a name key here.
And for example, name him Maximilian Schwarzmuller.
And add an email key here.
And that could be max@test.com,
which of course is a fake email address.
With that, we can hit Enter and this was inserted.
And I'm then going to repeat this command here
by pressing the up arrow.
And I'm only going to swap the data
and add a second author here, my colleague Manual Lorenz.
And use manual@test.com as an email address.
And also confirm this by hitting Enter.
So now, that was inserted as well.
And now, to confirm that this worked, we can of course,
run db.authers.find to find all the authors
that are stored in there.
And there, we got the two authors
with the automatically generated IDs.
So with that, we pre-populated our database as needed.
And we can now go back to our real website here,
to our NodeJS code more importantly.
And start connecting to MongoDB
and working with MongoDB there as well.