From the course: MongoDB Essential Training

Mongod

- [Instructor] A mongod is a daemon process for MongoDB. You could say it is the core unit of MongoDB. It handles data requests from the MongoDB shell or the MongoDB drivers, manages data access, and performs background management operations. Let's look at it in the shell. During this course, we're going to try out a few different deployment options for MongoDB. Please create a folder for this course called MongoDB essentials. CD into this folder and then inside this folder create another folder called mongod only. To get a MongoDB database up and running locally, all you need to do is run the command mongod and specify a directory for storage. You do that by parsing the command line argument dbpath and then specifying a folder for where the data can be stored. That's going to be the folder we just created, so we parse in mongod only. Right and then once we press enter, mongod will start running and if your output looks somewhat like this, it's all working fine. Generally, if something has gone wrong, you would see an error message and then you would see this process terminate. All right, let's talk about the default settings that MongoDB uses. By default, MongoDB will listen for connections on port 27017. The data, by default, will be stored in the directory data, db. However, this does not work on current macOS versions because the directory has become read-only. That's why I explicitly specified a different directory in this case. All right, so with MongoDB running, the next step is to interact with it with the MongoDB shell, so let's go back to the terminal. To open up the MongoDB shell, let's open a second terminal. And now, all you need to do is run mongosh, that will automatically connect to the default port on local host which is where we're currently running MongoDB so that will just work. Okay, so from the MongoDB shell, you can now run all of the normal MongoDB commands. So, one command that you can run for example is show databases, and that will then show you the default databases that are present in your deployment. You can also already store inquiry data so you could say db.test.insertone and then say, hello world and that would get inserted. And you can see up here something moved that's because the insert happened also on the mongod of course. All right, cool. Okay there's one thing that I need to make very clear, that is, do not run this in production. This MongoDB configuration only runs one mongod process, and that is just not good enough for any production usage. If you were to run this in production, anything happened to this one process, your database would be completely down. If the hard drive were to break your data may even be completely lost. We'll talk about how to avoid these issues in the next video.

Contents