Docs Menu
Docs Home
/
mongosh
/ /

View Shell Logs

The MongoDB Shell stores logs for each session. The default log location depends on your operating system.

1

Example

MongoDB Shell displays the log ID each time you open the shell.

$ mongosh
Current Mongosh Log ID: c2961dbd6b73b052671d9df0
Connecting to: mongodb://127.0.0.1:27017
Using MongoDB: 4.2.8
Using Mongosh: 2.4.0
2

MongoDB Shell saves the log for each session to your user's .mongodb/mongosh directory:

~/.mongodb/mongosh/<LogID>_log

Run the following command to view the log for a session:

cat ~/.mongodb/mongosh/<LogID>_log

Run the following command to tail the log for a session:

tail -f ~/.mongodb/mongosh/<LogID>_log

MongoDB Shell saves the log for each session to your user's C:\Users\<username>\AppData\Local\ directory:

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

Run the following PowerShell command to view the log for a session:

Get-Content %UserProfile%/AppData/Local/mongodb/mongosh/<LogID>_log

Run the following PowerShell command to tail the log for a session:

Get-Content %UserProfile%/AppData/Local/mongodb/mongosh/<LogID>_log

Tip

To change where MongoDB Shell writes logs, see Specify Log File Location.

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.

Back

Logs

On this page

  • Find your Log ID.
  • View the log for the session.