Coding

MongoDB Complete Introduction & Summary

  • 00:16:34 in that way but i actually want to
  • 00:16:36 connect differently so i'll bring this
  • 00:16:38 up again
  • 00:16:39 i will use the mongo shell and that is
  • 00:16:41 basically a
  • 00:16:42 javascript based program which you run
  • 00:16:45 in your terminal or
  • 00:16:46 command prompt on your machine where you
  • 00:16:49 can write all these query commands
  • 00:16:51 and connect to your server be that a
  • 00:16:53 local server or that cloud-based server
  • 00:16:55 here
  • 00:16:56 and therefore you can play around with
  • 00:16:58 it in a very very simple way
  • 00:17:00 without creating a whole node
  • 00:17:02 application just to play around with it
  • 00:17:05 we also got mongodb compass and we'll
  • 00:17:07 have a look at this in a while
  • 00:17:09 this is basically a tool which gives us
  • 00:17:11 a visual
  • 00:17:12 interface which is great but we want to
  • 00:17:14 use the console because there we write
  • 00:17:16 the queries pretty much as we'll
  • 00:17:18 also write them in our apps in our node
  • 00:17:21 or php or whatever it is apps
  • 00:17:23 we would connect to mongodb so therefore
  • 00:17:26 we'll have a look at compass later with
  • 00:17:27 the graphical ui for now
  • 00:17:29 let's simply use the setup where we
  • 00:17:32 write the code which is close to the
  • 00:17:33 code you would use in a real application
  • 00:17:36 here you have to choose your operating
  • 00:17:37 system and then download
  • 00:17:40 the shell first of all so this will now
  • 00:17:42 download it to my
  • 00:17:43 system and installing it is very simple
  • 00:17:47 you can view the detailed instructions
  • 00:17:48 here to then also find out how to
  • 00:17:50 connect
  • 00:17:51 for that you just have to choose the
  • 00:17:52 version and if you just downloaded it
  • 00:17:54 you'll use
  • 00:17:55 shell version 3.6 or later keep that
  • 00:17:58 open
  • 00:17:58 let's now install that shell
  • 00:18:02 and the installation will differ from
  • 00:18:04 operating system to operating system
  • 00:18:07 in the video description you also find a
  • 00:18:09 link with some information on how that
  • 00:18:10 works
  • 00:18:11 in the end on mac you just extract a
  • 00:18:14 file
  • 00:18:15 and then you get a folder which contains
  • 00:18:19 the shell and you can move that folder
  • 00:18:22 anywhere you want
  • 00:18:23 and simply navigate into that folder in
  • 00:18:25 your terminal
  • 00:18:26 and start it and you started with this
  • 00:18:30 command actually to connect to this
  • 00:18:32 cluster for that given user here and on
  • 00:18:35 windows it's very similar by the way
  • 00:18:38 so i navigated into that bin folder that
  • 00:18:40 was extracted on mac
  • 00:18:42 on windows you'll have an installer once
  • 00:18:44 you walk through that you'll also have a
  • 00:18:46 folder where the shell is installed
  • 00:18:48 and then you execute that mongo command
  • 00:18:51 which is in there you can just copy and
  • 00:18:53 paste in the command you got in that
  • 00:18:55 modal on the mongodb cluster but there
  • 00:18:57 is something you have to add
  • 00:18:59 on mac you have to add dot slash at the
  • 00:19:02 beginning
  • 00:19:03 now this will try to connect to your
  • 00:19:05 cluster and ask you for your password
  • 00:19:07 that password is something you set up
  • 00:19:10 for the user if you ever forgot it you
  • 00:19:12 can of course assign a new one
  • 00:19:13 and then enter that password here and it
  • 00:19:16 should now connect to your cluster
  • 00:19:18 now once this finished you should be
  • 00:19:20 connected to the cluster and therefore
  • 00:19:21 to the database server
  • 00:19:23 not to a single database now you can
  • 00:19:25 start running mongodb commands and of
  • 00:19:27 course you find all available commands
  • 00:19:29 in the official docs
  • 00:19:30 one useful one is show dbs it shows you
  • 00:19:33 all the databases you have on your
  • 00:19:34 cluster and if it's brand new
  • 00:19:36 you'll have these two now on mongodb
  • 00:19:39 which is pretty convenient you don't
  • 00:19:41 have to create databases with complex
  • 00:19:43 commands
  • 00:19:44 instead they are created on the fly when
  • 00:19:46 you need them you can switch to a
  • 00:19:48 database with the use command
  • 00:19:50 for example we can use first
  • 00:19:53 test here now we switch to the first
  • 00:19:55 test database even though that didn't