Skip to main content
Version: 7.0

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
  1. Right-click on the Start icon in the lower-left corner of the screen.
  2. Select “Windows PowerShell (Administrator)” from the context menu.
Using the Start menu
  1. Left-click on the Start icon in the lower-left corner of the screen.
  2. Type powershell
  3. Open PowerShell as “Administrator” by pressing Ctrl + Shift + Enter

Connect to the MongoDB shell:

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
danger

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:

use admin

Create a user, changing the login (user) and password (pwd) accordingly:

db.createUser({
user: "adminuser",
pwd: "password",
roles: [
{ role: "root", db: "admin" }
],
passwordDigestor: "server"
})
danger

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:

var cmdLineOpts = db.serverCmdLineOpts();
print("config: " + cmdLineOpts.parsed.config);

Edit the obtained configuration file by changing and adding the lines:

security:
authorization: enabled

Example of the edited file:

Example of edited MongoDB configuration file
danger

Note that indentation is a critical detail of the configuration file syntax.

Save changes and restart the MongoDB service in PowerShell:

net stop MongoDB
net start MongoDB

To verify, connect to the shell with authorization:

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.