View Shell Logs
The MongoDB Shell stores logs for each session. The default log location depends on your operating system.
View the log for the session.
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.