The MongoDB Shell stores logs for each session. The default log location depends on your operating system.MongoDB Shell存储每个会话的日志。默认日志位置取决于操作系统。
Find your Log ID.查找日志ID。
Example示例
MongoDB Shell displays the log ID each time you open the shell.每次打开Shell时,MongoDB Shell都会显示日志ID。
$ mongosh
Current Mongosh Log ID: c2961dbd6b73b052671d9df0
Connecting to: mongodb://127.0.0.1:27017
Using MongoDB: 4.2.8
Using Mongosh: 2.5.10View the log for the session.查看会话日志。
macOS and Linux
MongoDB Shell saves the log for each session to your user's MongoDB Shell将每个会话的日志保存到用户的.mongodb/mongosh directory:.mongodb/mongosh目录中:
~/.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>_logWindows
MongoDB Shell saves the log for each session to your user's MongoDB Shell将每个会话的日志保存到用户的C:\Users\<username>\AppData\Local\ directory:C:\Users\<username>\AppData\Local\目录:
UserProfile%/AppData/Local/mongodb/mongosh/<LogID>_log
Run the following PowerShell command to view the log for a session:运行以下PowerShell命令以查看会话的日志:
Get-Content %UserProfile%/AppData/Local/mongodb/mongosh/<LogID>_log
Run the following PowerShell command to tail the log for a session:运行以下PowerShell命令以跟踪会话的日志:
Get-Content %UserProfile%/AppData/Local/mongodb/mongosh/<LogID>_logTip
To change where MongoDB Shell writes logs, see Specify Log File Location.要更改MongoDB Shell写入日志的位置,请参阅指定日志文件位置。
Starting in MongoDB Shell 2.4.0, you can use the 从MongoDB Shell 2.4.0开始,您可以使用log.getPath() command to view the current log file location. For example:log.getPath()命令查看当前日志文件位置。例如:
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.路径中的十六进制值是当前会话的MongoDB Shell日志标识符。