Starting MongoDB Database Software
Learn how to start your MongoDB database software in Microsoft Windows, Linux, and MacOS.
Join the DZone community and get the full member experience.Join For Free
In this post, we will cover how to start MongoDB database software in the three most used platforms: Windows, Linux, and MacOS.
If you have just started with NoSQL databases, you might wonder how to evaluate whether MongoDB is a good fit for your application.
Percona provides a signed version of MongoDB called Percona Server for MongoDB with a couple of enterprise-grade features included free of charge that runs on all Linux flavors. We also support MongoDB (please check out our support page). But what if you're running a test on your study laptop (PC or not)? How do you easily start a mongod process for testing? Below, I demonstrate how to start MongoDB database software on the three most popular operating systems.
First of all, be aware of this hotfix.
You might need to restart the computer after applying the fix. Then, download the .zip file. The website only offers an MSI, but we don't want to install the binaries — we just want to run it.
After the download, use your favorite decompressing tool to extract the MongoDB executables. Then, cut the extracted folder to your Documents or C: or even a memory stick (but don't expect high performance):
Inside of the bin folder, create a data folder. We are going to use this folder to save our databases.
Now, we have everything we need to start the database. Open the CMD and run the following commands to start the database:
C:\mongodb\bin\mongod --dbpath c:\mongodb\bin\data
You will see an output like:
This means that the process is running.
In a different CMD, connect to the database using:
C:mongodbbinmongod --dbpath c:mongodbbindata
-quiet to omit the warnings:
And here we go! MongoDB is running on a windows machine!
MacOS and Linux Configuration
For macOS, the process is very similar to Windows. The difference is that we can take advantage of the extensive bash commands that the UNIX-like system offers.
Open the terminal. Go to our home/Downloads folder: cd ~/Downloads.
Download MongoDB for MacOS or Linux:
wget https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.3.tgz Download mongodb for Linux: wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.3.tgz untar the file: tar -xvzf mongodb-osx-ssl-x86_64-3.6.3.tgz Change the folder name to mongodb // just to make it easier mv mongodb-osx-x86_64-3.6.3/ ~/Downloads/mongodb Right now all the binaries are on ~/Downloads/mongodb/ Create a folder to save the database is in ~/Downloads/mongodb/bin/ mkdir ~/Downloads/mongodb/bin/data Start the mongod process ./mongod --dbpath data
The output must be similar to:
On a different tab, run:
At this point, you should be able to use MongoDB with the default options on MacOS or Linux.
Note that we aren't enabling authentication either configuring a replica set.
If we don't pass the
-quiet parameter, we will receive a few warnings like:
2018-03-16T14:26:20.868-0300 I CONTROL [initandlisten] I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. I CONTROL [initandlisten] I CONTROL [initandlisten] ** WARNING: This server is bound to localhost. I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server. I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning. I CONTROL [initandlisten]
For more information about how to configure those parameters, please refer to the following posts and/or documentation:
To stop the mongod process, use ctrl + c (on any operating system) in the server window.
If you enjoyed this article and want to learn more about MongoDB, check out this collection of tutorials and articles on all things MongoDB.
Published at DZone with permission of Adamo Tonete, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.