Docs Menu

Retrieve Shell Logs

On this page

  • View MongoDB Shell Logs
  • View MongoDB Shell Command History
  • Log Retention

MongoDB Shell uses ndjson 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.

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: 1.4.2
2

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

mongosh retains log files for 30 days. Log files older than 30 days are automatically deleted.

←  Client-Side Field Level Encryptionmongosh Usage →
Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.