Database Profiler Output

The database profiler captures data information about read and write operations, cursor operations, and database commands. To configure the database profile and set the thresholds for capturing profile data, see the Database Profiler section.

The database profiler writes data in the system.profile collection, which is a capped collection. To view the profiler’s output, use normal MongoDB queries on the system.profile collection.

Note

Because the database profiler writes data to the system.profile collection in a database, the profiler will profile some write activity, even for databases that are otherwise read-only.

Changed in version 3.4.

currentOp and the database profiler report the same basic diagnostic information for all CRUD operations, including the following:

These operations are also included in the logging of slow queries (see slowOpThresholdMs for more information about slow query logging).

Example system.profile Document

The documents in the system.profile collection have the following form. This example document reflects a find operation on a standalone mongod:

{
   "op" : "query",
   "ns" : "test.c",
   "command" : {
      "find" : "c",
      "filter" : {
         "a" : 1
      },
      "$clusterTime" : {
            "clusterTime" : Timestamp(1516119535, 1),
            "signature" : {
               "hash" : BinData(0,"h6fRyauI8KAejCbq4DvwvJAoJ1s="),
               "keyId" : NumberLong("6511683304255651841")
            }
      },
      "$db" : "test"
   },
   "keysExamined" : 2,
   "docsExamined" : 2,
   "cursorExhausted" : true,
   "numYield" : 0,
   "locks" : {
      "Global" : {
         "acquireCount" : {
            "r" : NumberLong(2)
         }
      },
      "Database" : {
         "acquireCount" : {
            "r" : NumberLong(1)
         }
      },
      "Collection" : {
         "acquireCount" : {
            "r" : NumberLong(1)
         }
      }
   },
   "nreturned" : 2,
   "responseLength" : 108,
   "protocol" : "op_msg",
   "millis" : 0,
   "planSummary" : "IXSCAN { a: 1 }",
   "execStats" : {
      "stage" : "FETCH",
      "nReturned" : 2,
      "executionTimeMillisEstimate" : 0,
      "works" : 3,
      "advanced" : 2,
      "needTime" : 0,
      "needYield" : 0,
      "saveState" : 0,
      "restoreState" : 0,
      "isEOF" : 1,
      "invalidates" : 0,
      "docsExamined" : 2,
      "alreadyHasObj" : 0,
      "inputStage" : {
         "stage" : "IXSCAN",
         "nReturned" : 2,
         "executionTimeMillisEstimate" : 0,
         "works" : 3,
         "advanced" : 2,
         "needTime" : 0,
         "needYield" : 0,
         "saveState" : 0,
         "restoreState" : 0,
         "isEOF" : 1,
         "invalidates" : 0,
         "keyPattern" : {
            "a" : 1
         },
         "indexName" : "a_1",
         "isMultiKey" : false,
         "multiKeyPaths" : {
            "a" : [ ]
         },
         "isUnique" : false,
         "isSparse" : false,
         "isPartial" : false,
         "indexVersion" : 1,
         "direction" : "forward",
         "indexBounds" : {
            "a" : [
               "[1.0, 1.0]"
            ]
         },
         "keysExamined" : 2,
         "seeks" : 1,
         "dupsTested" : 0,
         "dupsDropped" : 0,
         "seenInvalidated" : 0
      }
   },
   "ts" : ISODate("2015-09-03T15:26:14.948Z"),
   "client" : "127.0.0.1",
   "appName" : "MongoDB Shell",
   "allUsers" : [
         {
            "user" : "report1",
            "db" : "test"
         }
      ],
      "user" : "[email protected]"
}

The profile entry for update and delete contains the entire update/delete document applied to the named collection. Multiple update/delete documents will result in a profile entry for each document.

The following example reflects a single update operation on a collection named c.

{
   "op" : "update",
   "ns" : "test.c",
   "command" : {
      "q" : {
         "a" : 1
      },
      "u" : {
         "$set" : {
            "b" : 2
         }
      },
      "multi" : false,
      "upsert" : false
   },
   "keysExamined" : 2,
   "docsExamined" : 2,
   "nMatched" : 1,
   "nModified" : 1,
   ...
}

Output Reference

For any single operation, the documents created by the database profiler will include a subset of the following fields. The precise selection of fields in these documents depends on the type of operation.

Changed in version 3.2.0: system.profile.query.skip replaces the system.profile.ntoskip field.

Changed in version 3.2.0: The information in the system.profile.ntoreturn field has been replaced by two separate fields, system.profile.query.limit and system.profile.query.batchSize. Older drivers or older versions of the mongo shell may still use ntoreturn; this will appear as system.profile.query.ntoreturn.

Note

For the output specific to the version of your MongoDB, refer to the appropriate version of the MongoDB Manual.

system.profile. op

The type of operation. The possible values are:

  • command
  • count
  • distinct
  • geoNear
  • getMore
  • group
  • insert
  • mapReduce
  • query
  • remove
  • update
system.profile. ns

The namespace the operation targets. Namespaces in MongoDB take the form of the database, followed by a dot (.), followed by the name of the collection.

system.profile. command

Changed in version 3.6.

A document containing the full command object associated with this operation. If the command document exceeds 50 kilobytes, the document has the following form:

"command" : {
  "$truncated": <string>,
  "comment": <string>
}

The $truncated field contains a string summary of the document excluding the document’s comment field if present. If the summary still exceeds 50 kilobytes then it is further truncated, denoted by an ellipsis (…) at the end of the string.

The comment field is present if a comment was passed to the operation.

The following example output contains the command object for a find operation on a collection named items in a database named test:

"command" : {
  "find" : "items",
  "filter" : {
    "sku" : 1403978
  },
  "$db" : "test"
}

The following example output contains the command object for a getMore operation generated by a command with cursor id 80336119321 on a collection named items in a database named test:

"command" : {
  "getMore" : NumberLong("80336119321"),
  "collection" : "items",
  "$db" : "test"
}
system.profile. originatingCommand

Changed in version 3.6: For "getmore" operations which retrieve the next batch of results from a cursor, the originatingCommand field contains the full command object (e.g. find or aggregate) which originally created that cursor.

system.profile. cursorid

The ID of the cursor accessed by a query and getmore operations.

system.profile. keysExamined

Changed in version 3.2.0.

Renamed from system.profile.nscanned. The number of index keys that MongoDB scanned in order to carry out the operation.

In general, if keysExamined is much higher than nreturned, the database is scanning many index keys to find the result documents. Consider creating or adjusting indexes to improve query performance..

Changed in version 3.4.

keysExamined is available for the following commands and operations: