Authorization configuration in Windows Server
Connecting and creating user in MongoDB
Connecting to the Shell
Open PowerShell as an administrator:
Using the Start context menu
- Right-click on the Start icon in the lower-left corner of the screen.
- Select “Windows PowerShell (Administrator)” from the context menu.
Using the Start menu
- Left-click on the Start icon in the lower-left corner of the screen.
- Type
powershell - Open PowerShell as “Administrator” by pressing
Ctrl + Shift + Enter
Connect to the MongoDB shell:
- PowerShell
mongosh
Connection error to the shell
If after running the connection command you get an error:
mongosh : The term 'mongosh' is not recognized as the name of a cmdlet, function, script file, or operable program.
The MongoDB administration utilities are not located in the $PATH environment variable. To connect, you need to search for the mongosh.exe utility:
$mongoshPath = Get-ChildItem -Path "C:\" -Filter "mongosh.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1; $mongoshDirectory = $mongoshPath.DirectoryName; cd $mongoshDirectory
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 mongosh.exe utility is located.
Connect to the MongoDB shell:
.\mongosh.exe
Creating user
Switch to the admin database:
- PowerShell
use admin
Create a user, changing the login (user) and password (pwd) accordingly:
- PowerShell
db.createUser({
user: "adminuser",
pwd: "password",
roles: [
{ role: "root", db: "admin" }
],
passwordDigestor: "server"
})
The following characters are prohibited in the username and password as they may cause connection failures to MongoDB: . @ $ : % " ' / \ |
Enabling authorization and connecting Passwork
Enabling authorization in MongoDB
Edit the MongoDB configuration file to enable authorization by running the following commands in the shell to get its location:
- PowerShell
var cmdLineOpts = db.serverCmdLineOpts();
print("config: " + cmdLineOpts.parsed.config);
Edit the obtained configuration file by changing and adding the lines:
- PowerShell
security:
authorization: enabled
Example of the edited file:

Note that indentation is a critical detail of the configuration file syntax.
Save changes and restart the MongoDB service in PowerShell:
- PowerShell
net stop MongoDB
net start MongoDB
To verify, connect to the shell with authorization:
- PowerShell
mongosh "mongodb://adminuser:password@localhost:27017"
Configuring and connecting Passwork with authorization
Edit the Passwork configuration file C:\inetpub\wwwroot\passwork\init\config.env, specifying the username and password of the created user:
MONGODB_USERNAME=adminuser
MONGODB_PASSWORD=password
Save changes and refresh the Passwork page to verify the connection with MongoDB authorization.