For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Specify Log File Location

You can specify where MongoDB Shell writes log files. By default, MongoDB Shell saves the log for each session to your user's .mongodb/mongosh directory, which depends on your operating system:

Operating System
Default Log Location

macOS and Linux

~/.mongodb/mongosh/<LogID>_log

Windows

%UserProfile%/AppData/Local/mongodb/mongosh/<LogID>_log

To view the current log file location, use the config API to return the logLocation value:

config.get("logLocation")

After you modify your log file location, you must start a new MongoDB Shell session for the change to take effect.

Starting in MongoDB Shell 2.4.0, you can use the log.getPath() command to view the current log file location. For example:

log.getPath()

Example output:

/Users/jane.doe/.mongodb/mongosh/c2961dbd6b73b052671d9df0_log

The hexadecimal value in the path is the MongoDB Shell log identifier for the current session.

If you modify the default log file location, log files have a mongosh_ prefix before the session ID. For example, the log for session ID 67be0c0eb6227e211a1979e8 is saved as mongosh_67be0c0eb6227e211a1979e8_log.

If you use the default log file location, the file name does not include the mongosh_ prefix. For example, the log for session ID 67be0c0eb6227e211a1979e8 is saved as 67be0c0eb6227e211a1979e8_log.

To change the log file location, modify the logLocation configuration option. You can modify configuration options with the configuration API or a configuration file.

Important

Specify logLocation as an absolute filepath.

The following command uses the config API to set the logLocation setting to /path/to/log/directory:

config.set("logLocation", "/path/to/log/directory")
Setting "logLocation" has been changed

The following configuration file sets the logLocation setting to /path/to/log/directory:

mongosh:
logLocation: "/path/to/log/directory"