Coding

Node.js + Express – Tutorial – Setup MongoDB

  • 00:00:01 hi welcome back everyone after doing all
  • 00:00:04 this request session validation stuff
  • 00:00:07 we're finally reaching the point where
  • 00:00:09 it I think makes sense you store some
  • 00:00:12 data to well manipulate some data to it
  • 00:00:16 do more with the data than just dumping
  • 00:00:18 it after each of our dummy requests so
  • 00:00:21 we'll introduce the database on the
  • 00:00:23 server now no chess often used with
  • 00:00:27 MongoDB together with MongoDB but you
  • 00:00:30 can use it just fine with sequel
  • 00:00:32 databases as well but in this video we
  • 00:00:35 will have a look at how we install
  • 00:00:36 MongoDB which is a no sequel database so
  • 00:00:40 let's get started on the MongoDB
  • 00:00:42 homepage one way to be org we just
  • 00:00:45 download a MongoDB just pick your
  • 00:00:49 operating system hit the download button
  • 00:00:52 here you don't need to fill out this
  • 00:00:54 form then just save it wherever you want
  • 00:00:56 and let that we'll finish see you in a
  • 00:00:59 second okay my download just finished
  • 00:01:01 now I'm extracting this and just just
  • 00:01:05 happened on another window let me bring
  • 00:01:08 this in and now I'm inside the extracted
  • 00:01:11 folder here this is how this will look
  • 00:01:14 like you have to spine or a folder and
  • 00:01:16 some other files now in this binary
  • 00:01:19 folder you have the things you will use
  • 00:01:22 to work with with Mongo to bees or on
  • 00:01:25 Windows you have several executable
  • 00:01:27 files on Mac you can run these files
  • 00:01:29 where the bash command or over by the
  • 00:01:33 terminal and it's this will be for
  • 00:01:37 example Mongo D will be a server you
  • 00:01:40 start up Mongo will be declined with
  • 00:01:42 which you connect the server but why
  • 00:01:44 talk about it let's see this in action
  • 00:01:46 you may copy this whole file this whole
  • 00:01:50 folder excuse me – where whichever
  • 00:01:52 location you want on your operating
  • 00:01:54 systems don't store it where you want
  • 00:01:56 doesn't have to be in your downloads
  • 00:01:58 folder just be sure to navigate to the
  • 00:02:01 right folder when you're using it later
  • 00:02:03 in the terminal for example so in my
  • 00:02:07 case here let me open a terminal and
  • 00:02:10 here I navigated into my MongoDB
  • 00:02:14 a folder on Windows may just run the
  • 00:02:18 executable on Mac or Linux when I do is
  • 00:02:22 I run dot slash Mongo did you start our
  • 00:02:27 Mongo server and now it's running this
  • 00:02:31 you can see it's not exiting here
  • 00:02:33 because well it's continuing to run now
  • 00:02:37 I will open a second terminal window by
  • 00:02:40 the way all the installation process
  • 00:02:43 already finished as is just to show you
  • 00:02:45 how it works
  • 00:02:46 and in this window I'll also navigated
  • 00:02:48 into this MongoDB folder so in here I'll
  • 00:02:53 also navigate into the bin folder here I
  • 00:02:56 will run Mongo oops dot slash manga
  • 00:02:59 which is the client range this nicely
  • 00:03:04 here and now on the right I got the
  • 00:03:07 server running I'm not doing anything
  • 00:03:09 there and on the Left I have the client
  • 00:03:11 and of course later in our Express app
  • 00:03:13 we will let node or Express handle this
  • 00:03:17 but just to show you how you generally
  • 00:03:20 work with Mongo inside my client which
  • 00:03:24 is connected to the server I got running
  • 00:03:26 on the right I can type DB to see the
  • 00:03:29 current database I'm on and this is a
  • 00:03:32 test database what ships with MongoDB
  • 00:03:34 and here we can just well test some
  • 00:03:38 things try out some things so what all
  • 00:03:40 the years I want to insert something new
  • 00:03:43 I do this but having DB which refers to
  • 00:03:46 this test database then dot and now I
  • 00:03:49 will specify the name of the collection
  • 00:03:53 which I want to use MongoDB doesn't have
  • 00:03:55 tables
  • 00:03:56 it has collections because it's a no
  • 00:03:58 sequel database it has this JSON
  • 00:04:01 formatted approach and well therefore we
  • 00:04:04 talk of collections let's say I have a
  • 00:04:07 collection data and here let's say I
  • 00:04:10 want to answer the username I would do
  • 00:04:12 this by accessing my data collection
  • 00:04:14 with the dot notation on my database
  • 00:04:15 then dot insert and then I insert my
  • 00:04:21 JSON object so for example it has
  • 00:04:25 username
  • 00:04:26 oops name max close the object was
  • 00:04:32 parentheses hit enter and now you can
  • 00:04:35 see we wrote one entry to the database
  • 00:04:38 in order to see that data I can also
  • 00:04:40 query DB data not fine with empty
  • 00:04:45 parenthesis to see all the objects I
  • 00:04:48 have my database in this case only the
  • 00:04:50 user name and as you can see there was
  • 00:04:52 an ID automatically added to ders and
  • 00:04:55 via unique ID so and that's that for
  • 00:04:59 this video of course you can't do a lot
  • 00:05:00 more you can execute all the operations
  • 00:05:03 you want in your database database with
  • 00:05:05 the command shell command line here but
  • 00:05:08 we will do it as a node of course just
  • 00:05:10 wanted to make show you how to set up
  • 00:05:12 how it works that you got this server
  • 00:05:14 and client and the server the right
  • 00:05:18 terminal window is something we'll keep
  • 00:05:20 running for our development because we
  • 00:05:22 need that server and we're developing on
  • 00:05:24 our local machine at the moment but the
  • 00:05:26 client is something we won't eat in a
  • 00:05:28 future because we were not using this
  • 00:05:30 command line client or this MongoDB
  • 00:05:32 shell client but instead we will use
  • 00:05:36 Express and a respective MongoDB package
  • 00:05:41 see you in the next video where we will
  • 00:05:43 actually do this
  • 00:05:44 bye