Saturday, January 27, 2018

Install MongoDB from Tarball - Linux

Install MongoDB from Tarball - Linux

Here we gonna install MongoDB 3.2.18 using tarball approach, where we can give our own binary path and config file path.

Download the binary files



It will get downloaded in the home directory,


Extract the file from the downloaded archive

# tar -zxvf mongodb-linux-x86_64-3.2.18.tgz


Prerequisite to run mongo server

Create a data directory where the data should get stored,

# mkdir -p data/db
# cd data/db
# pwd

/home/ec2-user/data/db


Copy the binary path, where we extracted –

/home/ec2-user/mongodb-linux-x86_64-3.2.18/bin


Run the mongo server

# /home/ec2-user/mongodb-linux-x86_64-3.2.18/bin/mongod --dbpath /home/ec2-user/data/db

When click on enter, the server starts running listening to the default port  27017 as shown below –


As soon as you start the mongo server, the default files will get generated as shown below in the data directory.


Start the Mongo Client

Keep the server running in one command line and open another command line, run the below commands –

# /home/ec2-user/mongodb-linux-x86_64-3.2.18/bin/mongo


Done...








Friday, January 26, 2018

Install MongoDB using .rpm Packages (download and install) – Linux

Install MongoDB using .rpm Packages (download and install) – Linux

Here we gonna install MongoDB 3.2.16 by downloading the .rpm packages and installing, instead of having .repo files.

Download the rpm packages


sudo yumdownloader mongodb-org-3.2.16 mongodb-org-server-3.2.16 mongodb-org-shell-3.2.16 mongodb-org-mongos-3.2.16 mongodb-org-tools-3.2.16


It will get downloaded in the home directory,


Install the binaries

sudo yum install mongodb-org-3.2.16-1.el7.x86_64.rpm mongodb-org-mongos-3.2.16-1.el7.x86_64.rpm mongodb-org-server-3.2.16-1.el7.x86_64.rpm mongodb-org-shell-3.2.16-1.el7.x86_64.rpm mongodb-org-tools-3.2.16-1.el7.x86_64.rpm


When click on enter, the below screen will appear after the successful installation,


By default, after the installation the below mentioned files will be created –

/var/log/mongodb/mongod.log
/etc/mongod.conf – Configuration File

When we start the server, the server will start according to the configuration mentioned in /etc/mongod.conf file.

Configuration File – by default

dbpath - /var/lib/mongo
logpath - /var/log/mongodb/mongod.log
port – 27017

To start the server

# sudo service mongod start


You can check the mongo service by using the command,
# ps aux | grep mongo

To Start the client

Just type mongo in the same terminal, as we forked the process which is mentioned in the config file.

# mongo


Done...







Thursday, January 18, 2018

Install MongoDB using YUM Installer – Linux

Install MongoDB using YUM Installer – Linux

Here am gonna show you an example to install MongoDB 3.2 version using YUM installer UNIX

Configure the package management system (yum)

Create a /etc/yum.repos.d/mongodb-org-3.2.repo file so that you can install MongoDB directly, using yum.

For the latest stable release of MongoDB - Use the following repository file,

[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

# sudo vi /etc/yum.repos.d/mongodb-org-3.2.repo
Copy and paste the repo file here

# :wq



Install the MongoDB packages and associated tools.

To install the latest stable version of MongoDB, issue the following command:

# sudo yum install -y mongodb-org

Just trigger this command, after successful completion you can see the below screen –


By default, after the installation the below mentioned files will be created –

/var/log/mongodb/mongod.log
/etc/mongod.conf – Configuration File

When we start the server, the server will start according to the configuration mentioned in /etc/mongod.conf file.

Configuration File – by default

Dbpath - /var/lib/mongo
Logpath - /var/log/mongodb/mongod.log
Port – 27017

To start the server

# sudo service mongod start


You can check the mongo service by using the command,
# ps aux | grep mongo

To Start the client

Just type mongo in the same terminal, as we forked the process which is mentioned in the config file.

# mongo


Done...

Tuesday, January 16, 2018

Setting Up Environmental Variable for MongoDB - Windows

Environmental Variable Setup for MongoDB

Go till bin path  where the mongodb is installed– and copy it,


C:\Users\tommy\Downloads\mongo_server\bin


Steps to be followed,

1)     Ctrl + R
2)     Type sysdm.cpl, click ok


3)     The following page will appear, In that select Advanced and click on Environment Variables


              4)     Here select Path and click on Edit

                            

       
         5)     Click on New -> Paste the bin path and click on OK, OK and OK for the three                                      consecutive windows which is already opened.


          Done..


    Now to start the server
               
                1)     Go to command prompt, just type mongod and mention the dbpath if any or else it will 
                go to the default directory data/db – hit enter ( don’t need to specify the path till bin )

     mongod –dbpath  C:\Users\tommy\Downloads\mongo_data


           2)     The server starts running listening to the default port  27017


          To start the client,

                1)     Open another command prompt, just type mongo

                 


            Note: By setting up the Environmental Variable, we don’t have specify the entire mongo                                binary path – Just type in the binary name.


Done..







               



   








Sunday, January 14, 2018

MongoDB Binary Installation - Windows

Binary Installation





Community server -> windows -> All Version Binaries. When you do this, the below page will open in the other tab.




Here select the version of mongodb you need to install. As soon as you click on the link, it will get downloaded in the downloads folder


Extract the downloaded zip file

Prerequisite to run mongo server

Rename the extracted file if required to have the easy access and create a data directory as per your convenient – I have done it in downloads folder itself 

C:\Users\tommy\Downloads\mongo_server

                          

C:\Users\tommy\Downloads\mongo_data


Run MongoDB Server

Go till bin path  where the mongodb is installed– and copy it,

C:\Users\tommy\Downloads\mongo_server\bin



Copy the data directory as well,

C:\Users\tommy\Downloads\mongo_data






Open Command Prompt

Run the below commands,

# cd C:\Users\tommy\Downloads\mongo_server\bin
# mongod –dbpath C:\Users\tommy\Downloads\mongo_data



As soon as you executed this, a prompt shown below will occur -> Allow access



By then, the server starts running listening to the default port  27017 as shown below.



As soon as you start the mongo server, the default files will get generated as shown below in the data directory.



Start the Mongo Client

      1)      Keep the server running in one command prompt
      2)      Open another new command prompt

      Run the below commands,

# cd C:\Users\tommy\Downloads\mongo_server\bin
# mongo






You can query and see as well,



Done…












Tuesday, December 5, 2017

MongoDB MSI Installation on Windows - Step by step

MongoDB Installation Doc - Windows

https://www.mongodb.com/download-center#community -> Go to this link, you will see the below page



Community server -> If you want the latest version -> click on the Current Release  -> select the version based on the requirement(any) -> Click on Download link.

If you want to install the previous releases



Community Server -> Previous Releases -> Select the version -> Click the download link.


Go to downloads folder



Double click on the mongodb MSI file -> click on next



Accept the License Agreement -> click on next

     


Click on Complete

   

Click on Install
       
         

Click finish to complete the installation

Prerequisite to run mongo server

Create a folder C:\data\db

         


         


Run MongoDB Server

Go till bin path  where the mongodb is installed– and copy it,

C:\Program Files\MongoDB\Server\3.4\bin

         



Open Command Prompt

# cd C:\Program Files\MongoDB\Server\3.4\bin

             
# C:\Program Files\MongoDB\Server\3.4\bin>mongod

                
    

When you type mongod, the server will get started – It starts listening to the default port 27017 and default data location /data/db which we have created.

As soon as you start the mongo server, the default files will get generated as shown below,

     



Run the Mongo Client

1)      Keep the server running in one command prompt
2)      Open another new command prompt

# cd C:\Program Files\MongoDB\Server\3.4\bin

       

# C:\Program Files\MongoDB\Server\3.4\bin>mongo

     


You can query and see as well

   


Done…