MongoDB Installation guide

MongoDB Installation Guideline

 MongoDB on Ubuntu

Installation steps :

Step 1. Import the public key used by the package management system.
The Ubuntu package management tools (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys.

Command: sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

Step 2. Create a /etc/apt/sources.list.d/mongodb-enterprise.list file for MongoDB.
Create the list file using the command appropriate for your version of Ubuntu:

Ubuntu 14.04
Command: echo "deb [ arch=amd64 ] http://repo.mongodb.com/apt/ubuntu trusty/mongodb-enterprise/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list

Ubuntu 16.04
Command: echo "deb [ arch=amd64,arm64,ppc64el,s390x ] http://repo.mongodb.com/apt/ubuntu xenial/mongodb-enterprise/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list

Step 3. Reload local package database.
Issue the following command to reload the local package database:

Command: sudo apt-get update

Step 4. Install the MongoDB Enterprise packages.
Install MongoDB Enterprise version 3.6.

Command: sudo apt-get install -y mongodb-enterprise

 

Guide to Start MongoDB:

  1. Start MongoDB.
    Issue the following command to start mongod:
    Command: sudo service mongod start
  2. Verify that MongoDB has started successfully
    Verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading

example: [initandlisten] waiting for connections on port 27017
<port> is the port the mongod listens on. If you modified the net.port setting in the /etc/mongod.conf configuration file, the port may differ.

3.Stop MongoDB.
As needed, you can stop the mongod process by issuing the following command:
Command: sudo service mongod stop

4 Restart MongoDB.
Issue the following command to restart mongod:
Command: sudo service mongod restart

 

Reference : https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-ubuntu/

 

MongoDB on Windows

Installation steps :

Step 1. Download .msi file
Link: https://www.mongodb.com/download-center?_ga=2.266922382.1221638878.1526883555-405502849.1526532865#community

Step 2.
In Windows Explorer, locate the downloaded MongoDB .msi file, which typically is located in the default Downloads folder. Double-click the .msi file. The Windows Installer guides you through the installation process.

You may specify an installation directory if you choose the “Custom” installation option. (EX.: F:\Mongodb)

During the installation process, you will be given the option to install MongoDB Compass in addition to MongoDB Server. (Uncheck that option)

If you have installed MongoDB in F:\Mongodb then
F:\Mongodb\data\db folder should be there. If it does not exists create both folders like F:\Mongodb\data and F:\Mongodb\data\db

 

Guide to Start MongoDB:

Step 1: Open an Administrator command prompt.
Press the Win key, type cmd, and press Ctrl + Shift + Enter to run the Command Prompt as Administrator.

Execute the remaining steps from the Administrator command prompt.

Step 2: Create directories
Create directories for your database and log files:
mkdir F:\Mongodb\data\db
mkdir F:\Mongodb\data\log

Step 3: Create a configuration file
Create a file at F:\Mongodb\mongod.cfg that specifies both systemLog.path and storage.dbPath:

systemLog:
destination: file
path: F:\Mongodb\data\log\mongod.log
storage:
dbPath: F:\Mongodb\data\db

Step 4: Create the MongoDB service.
Command: sc.exe create MongoDB binPath= "\"F:\Mongodb\bin\mongod.exe\" --service --config=\"F:\Mongodb\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"

Step 5: Start the MongoDB service.
Command: net start MongoDB

Step 6: Verify that MongoDB has started successfully
Verify that MongoDB has started successfully by checking the log file at F:\Mongodb\data\log\mongod.log for the following line:

[initandlisten] waiting for connections on port 27017

Step 7: Connect to MongoDB.
To connect to MongoDB through the ~bin.mongo.exe shell, open another Command Prompt.

Command: "F:\Mongodb\bin\mongo.exe"

Step 8: Stop or remove the MongoDB service as needed.
To stop the MongoDB service, use the following command:

Command: net stop MongoDB
To remove the MongoDB service, first stop the service and then run the following command:

Command: sc.exe delete MongoDB

 

Reference: https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-windows/