Getting Started with MongoDB
MongoDB is a pretty awesome NoSQL database that has become super popular in the past few years. I’ve recently started learning MongoDB and I have to say I can understand it’s popularity. Modern applications are rapidly evolving and many will argue that relational databases are not designed to deal with the challenges that have presented themselves in modern development. MongoDB addresses issues like scalability, speed, and performance and it was built specifically for managing massive amounts of rapidly changing structured, semi-structured, unstructured and polymorphic data.
Now, let’s go over how to get MongoDB installed on your computer and get a local database up and running. I will be going over how to install Mongo on Windows, but the process is really similar across the major operating systems (Windows, Linux, Mac). Getting the database started is actually really simple and it just requires 3 easy steps.
1. Download + Install
First download and run the MongoDB installer for the latest stable release from here. Make a note of the installation path for Mongo (specifically the bin folder), if you choose the default installation path, you should find the bin folder at some path like C:\Program Files\MongoDB\Server\3.6\bin. You can open up a command prompt and cd to that directory once the installation is complete.
2. Create the Data Directory
Now that MongoDB is installed you can create the data directory which should like something like C:\data\db. By default, Mongo looks for these two files inside the root of the path that it was installed on (the C: path for most Windows users) but you can place the directory anywhere on your computer. Just note that if you put the files elsewhere you will need to let Mongo know when you start the server.
3. Start the Database
Now we can start the database by running mongod from the command prompt that you opened in the first step (inside C:\Program Files\MongoDB\Server\3.6\bin). If you put your data directory somewhere besides the absolute path of the drive from which you installed MongoDB, then you can run mongod --dbpath d:\data to start the database and d:\data represents the location of your data directory. Another option is to specify the data directory path inside a config file and you can read more about that here.