Even though I already showed it in the first course module, it's really important that you understand
how databases collections and documents are related. In a mongodb world,
you have one or more databases on your database server and each database can hold one or more collections,
a collection would be a table in a SQL database.
Now in that collection, you have these documents, multiple documents per collection and the documents
are really the data pieces
you're storing in your database. Now important, when working with mongodb, you will see in this module
already that the databases, the collections and the documents are all automatically created for you,
they are created implicitly when you start working with them,
when you start storing data. That is really convenient, later in the course we'll also learn a way of explicitly
creating new collections which allows you to configure them a bit further
but this is a cool feature which makes getting started super simple.
Now this is the core concept you always should keep in mind and the relation between databases collections
and documents you always should keep in mind.
And now with that out of the way, let's actually bring up that Mongo server again, connect through it through
our shell and again see how we can store data in there
and which kind of data that is.
I'm back in the terminal and I now again want to start my mongodb server, here on Mac, I'll do this with
sudo mongod
and make sure you watch the installation videos in the first course module to get this up and running
on Windows or Mac OS or Linux.
So with that command, I'm prompted to enter my password
and with this entered, it will start up my mongodb server using the wired tiger storage engine.
Now this is the server up and running and you need to keep this process running, so don't close this
window, don't quit this process yet, as you can see it's now waiting for new connections on port 27017
.
By the way if you wanted to use a different port or you're facing issues with this one, you can use a
different port
and now I did quit the server by hitting control and c, you can use a different port by specifying
--port when starting up the server
and then you can for example choose 27018
as a port
and now you see, it would be listening on that.
So that's just a tiny piece of information which can be useful in case you're using that default port
for something else.
So with that up and running, let's keep that up and running and open a new additional window in the terminal
and in there, you can now run Mongo without a d at the end
to use the mongo shell and automatically connect to the up and running server.
Now here however, I get a connect failed and that happened because by default, it tries to reach the server
on port 27017 which is obviously not the port
I'm running on.
So I can connect by using Mongo --port and then using that port where my server is running
and now you see this did connect successfully. With that we did connect again,
Now you can run cls in here and hit enter to clear the window,
I'm still in the shell here and if I scroll up, I see all the old output, cls just clears the window.
And now we can start running commands again and work with our database.