Error
Error Code:
30
MongoDB Error 30: Invalid Path Specified
Description
Error 30, 'Invalid Path', indicates that MongoDB encountered a path that is malformed, does not exist, or is inaccessible. This error commonly occurs when specifying file paths for configuration, data files, log files, or other operations requiring file system access.
Error Message
Invalid Path
Known Causes
4 known causesNon-existent Path
The specified directory or file path does not exist on the file system where MongoDB is running.
Incorrect Path Syntax
The path contains characters invalid for the operating system, or uses incorrect separators (e.g., backslashes on Linux).
Insufficient Permissions
MongoDB does not have the necessary read or write permissions for the specified path or its parent directories.
Typographical Errors
A simple typo in the path string prevents MongoDB from locating the intended resource.
Solutions
3 solutions available1. Verify File Paths in Configuration and Data Directories easy
Ensures MongoDB is configured to use valid and accessible file paths for its data, logs, and configuration.
1
Locate your MongoDB configuration file. This is typically named `mongod.conf` (Linux/macOS) or `mongod.cfg` (Windows). Common locations include `/etc/mongod.conf` or `/usr/local/etc/mongod.conf` on Linux/macOS, and `C:\Program Files\MongoDB\Server\<version>\bin\mongod.cfg` on Windows.
2
Open the configuration file in a text editor.
3
Review the `storage.dbPath` setting. Ensure this path exists and is accessible by the user running the MongoDB service. If it's incorrect, update it to the correct directory.
storage:
dbPath: /var/lib/mongodb
4
Review the `systemLog.path` setting (if present). Ensure this path exists and is writable by the MongoDB user.
systemLog:
path: /var/log/mongodb/mongod.log
5
If you are using a custom `--config` option when starting `mongod`, verify that the path provided to `--config` is correct and the file exists.
mongod --config /path/to/your/mongod.conf
6
On Windows, ensure the path specified in the MongoDB service configuration (accessible via `services.msc`) for the executable and configuration file is correct.
7
After making any necessary corrections, restart the MongoDB service.
sudo systemctl restart mongod
8
On Windows, use the Services management console or PowerShell.
Restart-Service MongoDB
2. Check Directory Permissions for MongoDB Data and Log Files medium
Confirms that the MongoDB process has the necessary read and write permissions for its data and log directories.
1
Identify the user account under which the MongoDB service is running. On Linux, this is often `mongodb`. On Windows, it might be `Network Service` or a dedicated service account.
2
Determine the `dbPath` and `systemLog.path` from your `mongod.conf` file (as described in Solution 1).
3
Verify the ownership and permissions of the `dbPath` directory. It should be owned by the MongoDB user and have read/write/execute permissions.
ls -ld /var/lib/mongodb
4
If permissions are incorrect, change them. For example, on Linux:
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chmod -R u+rwx /var/lib/mongodb
5
Verify the ownership and permissions of the `systemLog.path` directory and the log file itself. The MongoDB user needs write permissions.
ls -ld /var/log/mongodb/
ls -l /var/log/mongodb/mongod.log
6
If permissions are incorrect, change them. For example, on Linux:
sudo chown -R mongodb:mongodb /var/log/mongodb
sudo chmod -R u+rwx /var/log/mongodb
sudo chmod u+w /var/log/mongodb/mongod.log
7
On Windows, use File Explorer's Security tab or PowerShell to ensure the MongoDB service account has Full Control over the `dbPath` and log file directories.
$mongoUser = 'NETWORK SERVICE' # Or your specific service account
$dbPath = 'C:\Program Files\MongoDB\Server\<version>\data'
$logPath = 'C:\Program Files\MongoDB\Server\<version>\log'
$acl = Get-Acl $dbPath
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($mongoUser, 'FullControl', 'ContainerInherit, ObjectInherit', 'None', 'Allow')
$acl.AddAccessRule($rule)
Set-Acl $dbPath $acl
$acl = Get-Acl $logPath
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($mongoUser, 'FullControl', 'ContainerInherit, ObjectInherit', 'None', 'Allow')
$acl.AddAccessRule($rule)
Set-Acl $logPath $acl
8
Restart the MongoDB service after adjusting permissions.
sudo systemctl restart mongod
9
On Windows, use the Services management console or PowerShell.
Restart-Service MongoDB
3. Inspect Startup Logs for Specific Path Errors easy
Analyzes MongoDB's startup logs to pinpoint the exact invalid path causing the error.
1
Locate your MongoDB log file. This is typically specified by `systemLog.path` in your `mongod.conf` or a default location like `/var/log/mongodb/mongod.log` on Linux/macOS or in the MongoDB installation directory on Windows.
2
View the contents of the log file, paying close attention to entries around the time MongoDB failed to start.
tail -n 50 /var/log/mongodb/mongod.log
3
Look for messages that explicitly mention an invalid path, file not found, permission denied, or similar errors. The error message might be more specific than just 'Invalid Path'.
4
Identify the specific file or directory mentioned in the log entries. This could be related to `dbPath`, journal files, lock files, or the configuration file itself.
5
Once the problematic path is identified, proceed with the steps in Solution 1 (Verify File Paths) or Solution 2 (Check Directory Permissions) to correct the issue.