MongoDB:如何将所有查询记录到 Windows 上的日志文件

MongoDB: How to log all queries to log file on Windows

这个问题无法帮助我:MongoDB logging all queries

这是我的配置文件:

dbpath  = C:\mongodb\data
logpath = C:\mongodb\mongo.log
diaglog = 3                      
profile = 2
slowms  = 1

但是我的日志文件中没有查询。我做错了什么?

P.S: 我正在使用 mongodb 版本 v3.2.3

您有两个选项可以增加日志的详细程度。

  1. 增加配置文件中的日志详细程度。 systemLog.component.query.verbosity = 4 请参阅 systemLog.component.query.verbosity 文档

  2. db.setLogLevel(...) 请参阅 setLogLevel 文档。

您的最终配置文件应该如下所示

storage:
   dbPath: "C:\mongodb\data"

systemLog:
   destination: file
   path: "C:\mongodb\mongo.log"
   component:
       query:
           verbosity: 2

operationProfiling:
    slowOpThresholdMs: 100
    mode: slowOp

从 mongo shell 和 运行 连接: db.setLogLevel(2,"查询")