Monday, January 29, 2018

Steps to install chocolatey mongo db and setting up mongo server + node + Pm2

Supporting files n documents can be downloaded from:

Disable port 80 from inetmgs à bindings (change it to some other port eg 8082 while deploying a node app)


From the task scheduler, map the strartup script

Steps to install PM2:
PS C:\Windows\system32> npm install pm2 –g

Steps to install Node:
Download node .msi from https://nodejs.org/en/download/

Steps to install Mongo:
  •  Open power shell in admin mode
  •  Download chocolatey
               PS C:\WINDOWS\system32> Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  • Install Mongo DB (at C drive root)
PS C:\> choco install mongodb

Select Y on both the install questions, detailed below:
Do you want to run the script?([Y]es/[N]o/[P]rint):
Timeout or your choice of '' is not a valid selection.
You must select an answer
Do you want to run the script?([Y]es/[N]o/[P]rint): Y

mongodb package files install completed. Performing other installation steps.
The package mongodb wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[N]o/[P]rint): Y

  • Check the newly created directories (cd '.\Program Files\MongoDB\Server\3.4\bin)
PS C:\> cd '.\Program Files'
PS C:\Program Files> dir

1.      PS C:\Program Files> cd .\MongoDB
a.      PS C:\Program Files\MongoDB> dir

2.      PS C:\Program Files\MongoDB> cd .\Server
a.      PS C:\Program Files\MongoDB\Server> dir

3.      PS C:\Program Files\MongoDB\Server> cd .\3.4
a.      PS C:\Program Files\MongoDB\Server\3.4> dir

4.      PS C:\Program Files\MongoDB\Server\3.4> cd .\bin
a.      PS C:\Program Files\MongoDB\Server\3.4\bin> dir

  • Navigate to C directory and make folder for mongoDB and nested DB folder for project DB (tlv in this case)
PS C:\Program Files\MongoDB\Server\3.4\bin> cd /
PS C:\> mkdir mongodb-data

PS C:\> cd .\mongodb-data
PS C:\mongodb-data> dir
PS C:\mongodb-data> mkdir tlv

  • Create a mongo DB in the tlv directory (created above) using the below command (default the server would start at port=27017)
PS C:\> & '.\Program Files\MongoDB\Server\3.4\bin\mongod.exe' --dbpath C:\mongodb-data\tlv

Alternatively we can also specify port no while creating the mongo DB, details below (now mongo DB is listening at port = 34355, localhost:34355 )
PS C:\> & '.\Program Files\MongoDB\Server\3.4\bin\mongod.exe' --dbpath C:\mongodb-data\tlv --port 34355

Invoking Mongo as a service: "C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\3.6\mongod.cfg" –install

Sample mongod.cfg attached.

Mongo DB dump and restore
  • Dump command: PS C:\Program Files\MongoDB\Server\3.4\bin> .\mongodump
It would create the dump in C:\Program Files\MongoDB\Server\3.4\bin\dump
  • Restore DB: PS C:\Program Files\MongoDB\Server\3.4\bin> ./mongorestore /h localhost /db tlvdashboard 'C:\Users\Pahuja Saurabh\Desktop\tlvdashboard'

StartNodeService.xml (file to import in task scheduler)

1 comment: