-
-
Save akshaysura/335d97ab7526b610a7f9e15b285b7eca to your computer and use it in GitHub Desktop.
$mongoDbPath = "$env:SystemDrive\MongoDB" | |
$mongoDbConfigPath = "$mongoDbPath\mongod.cfg" | |
$url = "https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-3.2.7.zip" | |
$zipFile = "$mongoDbPath\mongo.zip" | |
$unzippedFolderContent ="$mongoDbPath\mongodb-win32-x86_64-2008plus-3.2.7" | |
if ((Test-Path -path $mongoDbPath) -eq $True) | |
{ | |
write-host "Seems you already installed MongoDB" | |
exit | |
} | |
Write-Host "Setting up directories..." | |
$temp = md $mongoDbPath | |
$temp = md "$mongoDbPath\log" | |
$temp = md "$mongoDbPath\data" | |
$temp = md "$mongoDbPath\data\db" | |
Write-Host "Setting up mongod.cfg..." | |
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "dbpath=$mongoDbPath\data\db`r`n") | |
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "logpath=$mongoDbPath\log\mongo.log`r`n") | |
[System.IO.File]::AppendAllText("$mongoDbConfigPath", "smallfiles=true`r`n") | |
Write-Host "Downloading MongoDB..." | |
$webClient = New-Object System.Net.WebClient | |
$webClient.DownloadFile($url,$zipFile) | |
Write-Host "Unblock zip file..." | |
Get-ChildItem -Path $mongoDbPath -Recurse | Unblock-File | |
Write-Host "Unzipping Mongo files..." | |
$shellApp = New-Object -com shell.application | |
$destination = $shellApp.namespace($mongoDbPath) | |
$destination.Copyhere($shellApp.namespace($zipFile).items()) | |
Copy-Item "$unzippedFolderContent\*" $mongoDbPath -recurse | |
Write-Host "Cleaning up..." | |
Remove-Item $unzippedFolderContent -recurse -force | |
Remove-Item $zipFile -recurse -force | |
Write-Host "Installing Mongod as a service..." | |
& $mongoDBPath\bin\mongod.exe --config $mongoDbConfigPath --install | |
Write-Host "Starting Mongod..." | |
& net start mongodb | |
Also because of MongoDB driver 1.10 in Sitecore 8.1 we are only limited to MongoDB 3.0.0 so modify the above scripts to 3.0.0.
https://docs.mongodb.com/ecosystem/drivers/csharp/#compatibility
Akshay, I am getting the below error. I tried to change policy for current user still not able to install. If you have any idea about this error, please let me know.
net.exe : The service name is invalid.
At D:\Sitecore\Sitecore_MongoDB_Install.ps1:47 char:1
- & net start mongodb
-
- CategoryInfo : NotSpecified: (The service name is invalid.:String) [], RemoteException - FullyQualifiedErrorId : NativeCommandError
More help is available by typing NET HELPMSG 2185.
Hey you can add bellow before download mongodb file on line 25 to avoid SSL/TLS error.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Fixed excepetion:
Exception calling "DownloadFile" with "2" argument(s): "The request was aborted: Could not create SSL/TLS secure
channel."
Sorry copy paste mistake for the line 48! ;)