Retrieve Shell Logs
MongoDB Shell uses Newline delimited JSON to store session logs.
Starting in mongosh
version 1.0.5, the log MongoDB Shell format
is updated to match the MongoDB server log format. For details, see
Log Messages.
You can view or tail the logs for a MongoDB Shell session based on its log ID.
Note
The MongoDB Shell redacts credentials from the command history and the logs.
View MongoDB Shell Logs
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
View MongoDB Shell Command History
MongoDB Shell saves a history of all commands you've run across sessions. When a new command is issued, it is added to the beginning of the history file.
Open the following file in a text editor to view the MongoDB Shell command history:
Operating System | Path to History File |
---|---|
macOS and Linux | ~/.mongodb/mongosh/mongosh_repl_history |
Windows | %UserProfile%/.mongodb/mongosh/mongosh_repl_history |
Log Retention
mongosh
retains up to 100 log files for 30 days. mongosh
automatically deletes log files older than 30 days.