Skip to main content
Version: 7.0

Windows Server

danger
  • If a replica set is used — please contact Passwork technical support for proper updating and data preservation.
  • If Passwork is installed on a virtual server, it is recommended to create a virtual OS snapshot before updating.

Preparation and removal of the outdated version

Creating a backup

By default, MongoDB administration utilities are not located in the $PATH environment variable. You need to search for the utilities using PowerShell.

Open PowerShell as administrator:

  • Right-click on the Start icon in the lower-left corner of the screen;
  • Select Windows PowerShell (Administrator) from the context menu.

Search for administration utilities:

$utilityPath = Get-ChildItem -Path "C:\" -Filter "mongodump.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1; $utilityDirectory = $utilityPath.DirectoryName; cd $utilityDirectory
info

If MongoDB and administration utilities were installed on a non-standard drive, you need to change the search path in the -Path parameter.

After execution, the current working directory will change to the new one where the utilities are located. To verify, run:

dir

Create a directory:

mkdir C:\backup\

Create a backup:

$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm"
.\mongodump --out "C:\backup\mongo-$timestamp"
info

The mongodump and mongorestore utilities are located in the same directory of MongoDB 4.x installation.

Removal

Stop the service:

net stop MongoDB

Delete the database service:

sc.exe delete "MongoDB"

Delete the directory with the database contents:

if (Test-Path "$env:ProgramFiles\MongoDB") {
Remove-Item -Path "$env:ProgramFiles\MongoDB" -Recurse -Force
Write-Host "MongoDB directory deleted." -ForegroundColor Green
} else {
Write-Host "MongoDB directory not found."
}

Search for MongoDB in the registry:

$mongo = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | Where-Object {
($_ | Get-ItemProperty).DisplayName -like "*MongoDB*"
}

Delete the registry entry:

if ($mongo) {
$mongo.PSPath | Remove-Item -Recurse -Force
Write-Host "Entry removed from registry" -ForegroundColor Green
} else {
Write-Host "Entry with DisplayName not found"
}

Installation and backup restoration

Installation

Download the MongoDB installer:

try {
(New-Object System.Net.WebClient).DownloadFile("https://repos.passwork.pro/repository/windows_packages/mongodb_database_latest.msi", "$env:SystemDrive\Windows\Temp\mongodb_database_latest.msi")
Write-Host "MongoDB successfully downloaded" -ForegroundColor Green
} catch {
Write-Host "Error downloading MongoDB: $_" -ForegroundColor Red
}
info

You can also download the installer manually

Install MongoDB by default:

try {
Start-Process -FilePath "msiexec.exe" -ArgumentList "/l*v", "$env:SystemDrive\Windows\Temp\mdbinstall.log", "/qb", "/i", "$env:SystemDrive\Windows\Temp\mongodb_database_latest.msi", "SHOULD_INSTALL_COMPASS=0", "ADDLOCAL=Router,ServerService" -Wait -ErrorAction Stop
} catch {
Write-Host "MongoDB installation error: $_." -ForegroundColor Red
}
info

To install MongoDB on another drive, add "INSTALLLOCATION=A:\MongoDB"

Create a directory for MongoDB administration utilities:

if (-not (Test-Path "$env:ProgramFiles\MongoDB\Tools\")) {
New-Item -ItemType Directory -Force -Path "$env:ProgramFiles\MongoDB\Tools\"
Write-Host "Directory successfully created" -ForegroundColor Green
} else {
Write-Host "Directory already exists"
}

Download administration utilities:

try {
(New-Object System.Net.WebClient).DownloadFile(
"https://repos.passwork.pro/repository/windows_packages/database_tools_latest.zip",
"$env:SystemDrive\Windows\Temp\database_tools_latest.zip"
)
Write-Host "Administration utilities downloaded" -ForegroundColor Green
} catch {
Write-Host "Error downloading administration utilities: $_" -ForegroundColor Red
}
info

You can also download the utilities manually

Extract the contents:

Expand-Archive `
-Path "$env:SystemDrive\Windows\Temp\database_tools_latest.zip" `
-DestinationPath "$env:ProgramFiles\MongoDB\Tools\"

Check connection to the shell:

cd "$env:ProgramFiles\MongoDB\Tools\"
.\mongosh mongodb://localhost:27017

Restoring the backup

If connection to the shell is successful, restore the databases from the backup:

cd "$env:ProgramFiles\MongoDB\Tools\"
.\mongorestore --drop "C:\backup\mongo-xxxx-xx-xx_xx-xx"

Open Passwork to verify proper operation.