Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A nice powershell that dowloads mongodb and installs it as windows service... this script is good for development machines.
Set-ExecutionPolicy RemoteSigned
$mongoDbPath = "C:\MongoDB"
$mongoDbConfigPath = "$mongoDbPath\mongod.cfg"
$url = "http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.4.9.zip"
$zipFile = "$mongoDbPath\mongo.zip"
$unzippedFolderContent ="$mongoDbPath\mongodb-win32-x86_64-2008plus-2.4.9"
if ((Test-Path -path $mongoDbPath) -eq $True)
{
write-host "Seems you already installed MongoDB"
exit
}
md $mongoDbPath
md "$mongoDbPath\log"
md "$mongoDbPath\data"
md "$mongoDbPath\data\db"
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "dbpath=C:\MongoDB\data\db`r`n")
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "logpath=C:\MongoDB\log\mongo.log`r`n")
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "smallfiles=true`r`n")
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "noprealloc=true`r`n")
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($url,$zipFile)
$shellApp = New-Object -com shell.application
$destination = $shellApp.namespace($mongoDbPath)
$destination.Copyhere($shellApp.namespace($zipFile).items())
Copy-Item "$unzippedFolderContent\*" $mongoDbPath -recurse
Remove-Item $unzippedFolderContent -recurse -force
Remove-Item $zipFile -recurse -force
& $mongoDBPath\bin\mongod.exe --config $mongoDbConfigPath --install
& net start mongodb
@jobsamuel

This comment has been minimized.

Copy link

jobsamuel commented Sep 14, 2014

Thanks for this Serdar!

@NTiering

This comment has been minimized.

Copy link

NTiering commented Jun 18, 2015

nice

@marcoonderstal

This comment has been minimized.

Copy link

marcoonderstal commented Nov 13, 2015

Thanks, super. I have made this part of our build & destroy based continuous integration setup

@Jauneetsingh

This comment has been minimized.

Copy link

Jauneetsingh commented Mar 8, 2016

Thanks....Good one

@dbouch4009

This comment has been minimized.

Copy link

dbouch4009 commented Oct 10, 2017

I had to use Start-Service mongodb in my script, but otherwise perfect. Thank you!!

@shiv16swaraj

This comment has been minimized.

Copy link

shiv16swaraj commented Mar 21, 2018

Thanks.. Can you provide the uninstallation script for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.