MongoDB (part 1): installation on Windows, macOS, Raspberry Pi [Exclusive Guide]

1:14 pm November 14, 201612384

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

mongodb windows installation

you can install everything (Complete)

 mongodb windows installation 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.

mongodb windows installation partielle

installation starts
mongodb windows installation progression

installation is complete, exit the installer by clicking Finish.

mongodb windows installation terminee

the files are installed in a directory MongoDB in programs (Program Files). A subdirectory is created for each version. [AllprogramsMongotofindforexampleatthefollowingpath:

 C:Program FilesMongoDBServer3.2bin

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.

mongodb windows variable environnement path data db

in the dialog box that opens, add a semicolon followed the path to the binary. Validate by pressing OK.

mongodb windows variable environnement path data db

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] 

start MongoDB

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.

mongodb windows start mongod firewall autoriser acces

the database is started and ready to receive connections from clients on the port 27017 by default.

mongodb windows start mongod --dbpath --storeEngine=mmapv1

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

 mongodb invite commande administrateur

create the service using sc.exe

the first method is to use sc.exe . Run the command

 sc.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. "

mongodb-windows-sc-exe-create

remove the service with sc.exe

the following command to delete the service

sc.exe delete

which gives for example in our case

 sc.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

- serviceName : Windows (only of alphanumeric characters without space) service name

- serviceDisplayName : (optional) name displayed in the list of services. Put in quotation marks if the name contains spaces.

- serviceDescription : (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 example

C:MongoDBbinmongod.exe - install - serviceName "MongoDB"-serviceDisplayName "MongoDB" - serviceDescription "MongoDB on port 27017" - newspaper - logpath c:datalogmongo.log

2016-11-03_12h03_20

delete the MongoDB service

to remove the service just run this command.

started menu, find and launch Services Manager.

 mongodb windows rechercher services

the MongoDB service (according to the assigned name) is present in the list but it does not start automatically after installation.

 mongodb service windows

for this made right click then start

mongodb demarrer manuellement service

now it is running

mongodb service demarre

now you can start with the command client mongo .

mongodb client connecte

versionWe Mac OS tested : 10.11.6 (El Captain).

MongoDB is installed on macOS using Brew . BREW is a package manager for Mac ( project official page).

node-red mongodb brew

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 

it's done.

now you need to create a directory for data

 mkdir 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 start

 mongod - 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 applications

 sudo 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 command

 sudo service - status-all 

a more brackets means that the service is well underway.

raspbian sudo --service-all mongodb runing

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 [1]: Started year object/document-oriented database.
Nov. 03 14:50:22 raspberrypi mongod [458]: all output going to: /var/log/mongodb/mongo...og nov. 03 14:59:52 raspberrypi systemd [1]: Stopping year object/document-oriented database... nov. 03 14:59:52 raspberrypi systemd [1]: Stopped year object/document-oriented database.
Hint: Some lines were ellipsized, use-l to show in full.

if it is not started, run this command

 sudo service start mongodb 

to interrupt service

 sudo 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…).

program (command) function
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

Sources