MongoDB (part 1): installation on Windows, macOS, Raspberry Pi [Exclusive Guide]
MongoDB is an Open Source oriented document database. Unlike a relational database classic in which the data is organized according to a schema (tables, fields, data types) and put into relation with each other, it stores the data in a MongoDB database in a document in the JSON style, IE in the form key: value.
the main advantage of the NoSQL databases is the absence of schema . There is no need to define the tables, fields of data (or data type) and the relationships between the tables (fields). A collection (the equivalent of a table) can contain different documents. Each document can have a number of field, a size, a different content from one document to the other. This architecture for many other advantages:
- the structure of a document can change , the structure is not fixed. Just to update a document to add / remove information. It is much more flexible than to modify fields in a relational database.
- there not links complexes between documents.
- MongoDB is able to complex searches as simply and effectively as a SQL query.
- MongoDB is designed to support the scalability . MongoDB is suitable for very large it projects. To learn more about performance, read this extensive article published on Ippon Technology blog . [
Windows version tested : 10 (32-bit)
before you download the version that matches your system, run this command
C: > wmic os get osarchitecture OSArchitecture 64 - bit C:>
the 32 bit version of MongoDB support only the databases less than 2 GB. That’s enough to make tests or small personal developments.
download the latest version of MongoDB from this address https://www.mongodb.org/downloads since the Community Server tab.
running the installer
you can install everything (Complete)
or only the desired components (Custom). In view of the necessary size (322MB), so everything install. Nothing prevents you to choose another directory for installation. Since the Custom option, click on Browse… to indicate (and create if needed) a different installation folder.
note. The subdirectory bin is created automatically at installation.
installation is complete, exit the installer by clicking Finish.
the files are installed in a directory MongoDB in programs (Program Files). A subdirectory is created for each version. [AllprogramsMongotofindforexampleatthefollowingpath:
now to add this path in environment variables. Open the menu started and enter variable . In the list of results, open “edit the system environment variables.
in the dialog box that opens, add a semicolon followed the path to the binary. Validate by pressing OK.
now, open the computer and create a directory data to the root then a db inside directory. You can also run this command in the command prompt. We want to create a directory for the logs (log). [
md md datalog[19459015datadb]
run the following command (don't forget to fix the path that matches your configuration) to start the MongoDB server. Need to set the path in quotes if it contains spaces. It must specify the path to the database (on the first launch).
attention. For 32-bit Windows, it is necessary to add an extra option - storageEngine = mmapv1"C:Program FilesMongoDBServer3.2binmongod.exe" - dbpath C:datadb - storageEngine = mmapv1
the first launch of MongoDB, you will need to allow access from Windows Firewall.
the database is started and ready to receive connections from clients on the port 27017 by default.
create a configuration mongod.cfg file
one can also go even further and create a configuration file mongod.cfg in Bin .
open a text editor and paste this basic configuration (Customize the paths and the storageEnegine which corresponds to your configuration).
save UTF-8 to format. If you don't have administrator rights, save the file in documents and then move it manually in the Bin directory mongodb.
once everything is ready, run mongod like this."C:Program FilesMongoDBServer3.2binmongod.exe"
to know in detail all the options available, go to this page https://docs.mongodb.com/v3.0/reference/configuration-options/
install the MongoDB service
now, we would like to although MongoDB runs automatically when Windows starts. " It is very easy, just install the service.
open a command prompt in Administrator
create the service using sc.exe
the first method is to use sc.exe . Run the commandsc.exe create MongoDB binPath = "C:mongodbbinmongod.exe - service - config="C:mongodbmongod.cfg "" DisplayName = "MongoDB" start = "auto"
[sc] message createService success (s) is returned if the service was successfully added. "
remove the service with sc.exe
the following command to delete the service
which gives for example in our casesc.exe delete MongoDB
create the service with the install option
order mongod accepts the option - install for installing MongoDB as a Windows service or - remove to uninstall the service as well as
- install: starts installing MongoDB as a Windows service
- remove: removes the Windows service
:Windows (only of alphanumeric characters without space) service name
:(optional) name displayed in the list of services. Put in quotation marks if the name contains spaces.
:(optional) brief description of the service. Put in quotes if there are spaces.
- logpath: (required for install) path to the journal
- journal (recommended): activates the log
what gives for exampleC:MongoDBbinmongod.exe - install - serviceName "MongoDB"-serviceDisplayName "MongoDB" - serviceDescription "MongoDB on port 27017" - newspaper - logpath c:datalogmongo.log
delete the MongoDB service
to remove the service just run this command.
started menu, find and launch Services Manager.
the MongoDB service (according to the assigned name) is present in the list but it does not start automatically after installation.
for this made right click then start
now it is running
now you can start with the command client mongo .
versionWe Mac OS tested : 10.11.6 (El Captain).
open a Terminal and paste this command/ usr/bin/ruby EI "$(curl-fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
answer the questions to complete the installation of Brew on your Mac.
once installed, run this command to install MongoDB.brew install mongodb
now you need to create a directory for datamkdir Pei/data/db
go to the finder and also give rights to reading and writing (for all users) to the file data. Cmd + I then identify yourself by pressing the lock and finally to change rights.
now, start with the option - dbpath first startmongod - dbpath/data/db
on Raspberry Pi, MongoDB is still limited to the 32-bit version, and so as a result to a maximum 2GB database. It will be therefore reserved tests, learning or small applicationssudo apt - get update sudo apt - get upgrade sudo apt - get install mongodb-server
binary files located in the directory
/ usr/bin /.The data files are in the folder
/ var/lib/mongodb /
the MongoDB service starts as soon as the end of the installation. To check if it is started, run the commandsudo service - status-all
a more brackets means that the service is well underway.
or sudo service mongodb status
[$19459030][email protected]:~ sudo service mongodb status ● mongodb.service - year object/document-oriented database Loaded: loaded (/ lib/systemd/system/mongodb.service; enabled) Active: inactive (dead) since game.] 2016-11-03 14:59:52 THIS; 2 min 10s ago Docs: man: mongod (1) Process: 458 ExecStart = / usr/bin/mongod - config /etc/mongodb.conf (code = exited, status = 0/SUCCESS) hand PID: 458 (code = exited, status = 0/SUCCESS) nov. 03 14:50:19 raspberrypi systemd : Started year object/document-oriented database.
Nov. 03 14:50:22 raspberrypi mongod : all output going to: /var/log/mongodb/mongo...og nov. 03 14:59:52 raspberrypi systemd : Stopping year object/document-oriented database... nov. 03 14:59:52 raspberrypi systemd : Stopped year object/document-oriented database.
Hint: Some lines were ellipsized, use-l to show in full.
if it is not started, run this commandsudo service start mongodb
to interrupt servicesudo service mongodb stop
you can now access the database from the client mongo.
MongoDB consists of some server (mongod) and a customer (mongo) that we will discover more in detail in the second part of this series of articles. Several utilities are also available (monitoring, import/export, performance…).
|mongod||the MongoDB database server|
|mongo||Client. Allows to run all Mongo since a Shell commands|
|mongostat, mongotop||monitoring utilities|
|mongodump , mongorestore , mongoexport , mongoimport||utility to import / export|
|bsondump , mongofiles , mongooplog , mongoperf||utilities|