Database Profiler Output

The database profiler captures data information about read and writeoperations, cursor operations, and database commands. To configure thedatabase 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 thesystem.profile collection in adatabase, the profiler will profile some write activity, even fordatabases that are otherwise read-only.

Changed in version 3.4.

currentOp and thedatabase profiler report the samebasic diagnostic information for all CRUD operations, including thefollowing:

These operations are also included in the logging ofslow queries (see slowOpThresholdMs formore information about slow query logging).

Example system.profile Document

The following presents some sample documents found in thesystem.profile collection foroperations on a standalone:

  • Find Operation
  • Update Operation

The following document in the system.profile reflects a find operation:

  1. {
  2. "op" : "query",
  3. "ns" : "test.report",
  4. "command" : {
  5. "find" : "report",
  6. "filter" : { "a" : { "$lte" : 500 } },
  7. "lsid" : {
  8. "id" : UUID("5ccd5b81-b023-41f3-8959-bf99ed696ce9")
  9. },
  10. "$db" : "test"
  11. },
  12. "cursorid" : 33629063128,
  13. "keysExamined" : 101,
  14. "docsExamined" : 101,
  15. "fromMultiPlanner" : true,
  16. "numYield" : 2,
  17. "nreturned" : 101,
  18. "queryHash" : "811451DD",
  19. "planCacheKey" : "759981BA",
  20. "locks" : {
  21. "Global" : {
  22. "acquireCount" : {
  23. "r" : NumberLong(3),
  24. "w" : NumberLong(3)
  25. }
  26. },
  27. "Database" : {
  28. "acquireCount" : { "r" : NumberLong(3) },
  29. "acquireWaitCount" : { "r" : NumberLong(1) },
  30. "timeAcquiringMicros" : { "r" : NumberLong(69130694) }
  31. },
  32. "Collection" : {
  33. "acquireCount" : { "r" : NumberLong(3) }
  34. }
  35. },
  36. "storage" : {
  37. "data" : {
  38. "bytesRead" : NumberLong(14736),
  39. "timeReadingMicros" : NumberLong(17)
  40. }
  41. },
  42. "responseLength" : 1305014,
  43. "protocol" : "op_msg",
  44. "millis" : 69132,
  45. "planSummary" : "IXSCAN { a: 1, _id: -1 }",
  46. "execStats" : {
  47. "stage" : "FETCH",
  48. "nReturned" : 101,
  49. "executionTimeMillisEstimate" : 0,
  50. "works" : 101,
  51. "advanced" : 101,
  52. "needTime" : 0,
  53. "needYield" : 0,
  54. "saveState" : 3,
  55. "restoreState" : 2,
  56. "isEOF" : 0,
  57. "docsExamined" : 101,
  58. "alreadyHasObj" : 0,
  59. "inputStage" : {
  60. ...
  61. }
  62. },
  63. "ts" : ISODate("2019-01-14T16:57:33.450Z"),
  64. "client" : "127.0.0.1",
  65. "appName" : "MongoDB Shell",
  66. "allUsers" : [
  67. {
  68. "user" : "someuser",
  69. "db" : "admin"
  70. }
  71. ],
  72. "user" : "someuser@admin"
  73. }

The profile entry for update (anddelete) operation contains the entire updatecommand.

The following example reflects an updateoperation on a collection named report.

  1. {
  2. "op" : "update",
  3. "ns" : "test.report",
  4. "command" : {
  5. "q" : { },
  6. "u" : { "$rename" : { "a" : "b" } },
  7. "multi" : true,
  8. "upsert" : false
  9. },
  10. "keysExamined" : 0,
  11. "docsExamined" : 25000,
  12. "nMatched" : 25000,
  13. "nModified" : 25000,
  14. "keysInserted" : 25000,
  15. "keysDeleted" : 25000000,
  16. "numYield" : 6985,
  17. "locks" : {
  18. "Global" : {
  19. "acquireCount" : { "r" : NumberLong(6986), "w" : NumberLong(13972) }
  20. },
  21. "Database" : {
  22. "acquireCount" : { "w" : NumberLong(6986) },
  23. "acquireWaitCount" : { "w" : NumberLong(1) },
  24. "timeAcquiringMicros" : { "w" : NumberLong(60899375) }
  25. },
  26. "Collection" : {
  27. "acquireCount" : { "w" : NumberLong(6986) }
  28. },
  29. "Mutex" : {
  30. "acquireCount" : { "r" : NumberLong(25000) }
  31. }
  32. },
  33. "storage" : {
  34. "data" : {
  35. "bytesRead" : NumberLong(126344060),
  36. "bytesWritten" : NumberLong(281834762),
  37. "timeReadingMicros" : NumberLong(94549),
  38. "timeWritingMicros" : NumberLong(139361)
  39. }
  40. },
  41. "millis" : 164687,
  42. "planSummary" : "COLLSCAN",
  43. "execStats" : {
  44. "stage" : "UPDATE",
  45. "nReturned" : 0,
  46. "executionTimeMillisEstimate" : 103771,
  47. "works" : 25003,
  48. "advanced" : 0,
  49. "needTime" : 25002,
  50. "needYield" : 0,
  51. "saveState" : 6985,
  52. "restoreState" : 6985,
  53. "isEOF" : 1,
  54. "nMatched" : 25000,
  55. "nWouldModify" : 25000,
  56. "wouldInsert" : false,
  57. "inputStage" : {
  58. "stage" : "COLLSCAN",
  59. "nReturned" : 25000,
  60. "executionTimeMillisEstimate" : 0,
  61. "works" : 25002,
  62. "advanced" : 25000,
  63. "needTime" : 1,
  64. "needYield" : 0,
  65. "saveState" : 31985,
  66. "restoreState" : 31985,
  67. "isEOF" : 1,
  68. "direction" : "forward",
  69. "docsExamined" : 25000
  70. }
  71. },
  72. "ts" : ISODate("2019-01-14T23:33:01.806Z"),
  73. "client" : "127.0.0.1",
  74. "appName" : "MongoDB Shell",
  75. "allUsers" : [
  76. {
  77. "user" : "someuser",
  78. "db" : "admin"
  79. }
  80. ],
  81. "user" : "someuser@admin"
  82. }

Output Reference

For any single operation, the documents created by the databaseprofiler will include a subset of the following fields. The preciseselection of fields in these documents depends on the type ofoperation.

Starting in MongoDB 4.2 (and in 4.0.9), for slow operations, the profilerentries anddiagnostic log messages includestorage information.

Note

For the output specific to the version of your MongoDB, refer tothe 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 MongoDBtake the form of the database, followed by a dot (.),followed by the name ofthe collection.
  • system.profile.command

Changed in version 3.6.

A document containing the full command object associated with thisoperation.

For example, the following output contains the command object for afind operation on a collection named items in adatabase named test:

  1. "command" : {
  2. "find" : "items",
  3. "filter" : {
  4. "sku" : 1403978
  5. },
  6. ...
  7. "$db" : "test"
  8. }

The following example output contains the command object for agetMore operation generated bya command with cursor id 19234103609 on a collection nameditems in a database named test:

  1. "command" : {
  2. "getMore" : NumberLong("19234103609"),
  3. "collection" : "items",
  4. "batchSize" : 10,
  5. ...
  6. "$db" : "test"
  7. },

If the command document exceeds 50 kilobytes, thedocument has the following form:

  1. "command" : {
  2. "$truncated": <string>,
  3. "comment": <string>
  4. }

The $truncated field contains a string summary of the document excludingthe document’s comment field if present. If the summary still exceeds50 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.

  • system.profile.originatingCommand

Changed in version 3.6.

For "getmore" operations which retrieve the next batch ofresults from a cursor, the originatingCommand field contains thefull command object (e.g. find or aggregate) which originallycreated that cursor.

  • system.profile.cursorid
  • The ID of the cursor accessed by a query and getmoreoperations.
  • system.profile.keysExamined

Changed in version 3.2.0.

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

In general, if keysExamined is much higherthan nreturned, the database is scanning manyindex keys to find the result documents. Consider creating oradjusting indexes to improve query performance..

Changed in version 3.4.

keysExamined is available for the following commands andoperations:

  • system.profile.docsExamined

Changed in version 3.2.0: Renamed from system.profile.nscannedObjects.

The number of documents in the collection that MongoDB scanned inorder to carry out the operation.

Changed in version 3.4.

docsExamined is available for the following commands andoperations:

  • system.profile.hasSortStage

Changed in version 3.2.0: Renamed from system.profile.scanAndOrder.

hasSortStage is a boolean that is truewhen a query cannot use the ordering in the index to return therequested sorted results; i.e. MongoDB must sort the documents afterit receives the documents from a cursor. The field only appears whenthe value is true.

Changed in version 3.4.

hasSortStage is available for the following commands andoperations:

  • system.profile.usedDisk

New in version 4.2.

A boolean that indicates whether any aggregation stage wrote data totemporary files due to memory restrictions.

Only appears if usedDisk is true.

  • system.profile.ndeleted
  • The number of documents deleted by the operation.
  • system.profile.ninserted
  • The number of documents inserted by the operation.
  • system.profile.nMatched

New in version 2.6.

The number of documents that match the system.profile.querycondition for the update operation.

  • system.profile.nModified

New in version 2.6.

The number of documents modified by the update operation.

  • system.profile.upsert
  • A boolean that indicates the update operation’s upsert optionvalue. Only appears if upsert is true.
  • system.profile.fromMultiPlanner

New in version 3.2.5.

A boolean that indicates whether the query planner evaluated multipleplans before choosing the winning execution plan for the query.

Only present when value is true.

  • system.profile.replanned

New in version 3.2.5.

A boolean that indicates whether the query system evicted a cachedplan and re-evaluated all candidate plans.

Only present when value is true.

  • system.profile.keysInserted
  • The number of index keys inserted for a given write operation.
  • system.profile.keysDeleted
  • Removed in 3.4.

The number of index keys the update changed inthe operation. Changing an index key carries a small performancecost because the database must remove the old key and inserts a newkey into the B-tree index.

  • system.profile.writeConflicts

New in version 3.0.0.

The number of conflicts encountered during the write operation; e.g.an update operation attempts to modify the same document asanother update operation. See also write conflict.

  • system.profile.numYield
  • The number of times the operation yielded to allow other operationsto complete. Typically, operations yield when they need access todata that MongoDB has not yet fully read into memory. This allowsother operations that have data in memory to complete while MongoDBreads in data for the yielding operation. For more information,see the FAQ on when operations yield.
  • system.profile.queryHash
  • A hexadecimal string that represents a hash of the queryshape and is dependent only on the query shape. queryHash canhelp identify slow queries (including the query filter of writeoperations) with the same query shape.

Note

As with any hash function, two different query shapes may resultin the same hash value. However, the occurrence of hashcollisions between different query shapes is unlikely.

For more information on queryHash and planCacheKey, seequeryHash and planCacheKey.

New in version 4.2.

  • system.profile.planCacheKey
  • A hash of the key for the plan cache entry associated with the query.

Unlike the queryHash, theplanCacheKey is a function ofboth the query shape and the currently available indexes forthat shape. That is, if indexes that can support the queryshape are added/dropped, the planCacheKey value may changewhereas the queryHash value would not change.

For more information on queryHash and planCacheKey, seequeryHash and planCacheKey.

New in version 4.2.

  • system.profile.locks

New in version 3.0.0: locks replaces the lockStats field.

The system.profile.locks provides information for variouslock types and lock modes heldduring the operation.

The possible lock types are:

Lock TypeDescriptionParallelBatchWriterModeRepresents a lock for parallel batch writer mode.

In earlier versions, PBWM information was reported as part ofthe Global lock information.

New in version 4.2.

ReplicationStateTransitionRepresents lock taken for replica set member state transitions.

New in version 4.2.

GlobalRepresents global lock.DatabaseRepresents database lock.CollectionRepresents collection lock.MutexRepresents mutex.MetadataRepresents metadata lock.oplogRepresents lock on the oplog.

The possible locking modes for the lock types are as follows:

Lock ModeDescriptionRRepresents Shared (S) lock.WRepresents Exclusive (X) lock.rRepresents Intent Shared (IS) lock.wRepresents Intent Exclusive (IX) lock.

The returned lock information for the various lock types include:

  • system.profile.locks.acquireCount
  • Number of times the operation acquired the lock in the specifiedmode.

  • system.profile.locks.acquireWaitCount

  • Number of times the operation had to wait for theacquireCount lock acquisitionsbecause the locks were held in a conflicting mode.acquireWaitCount is less than orequal to acquireCount.

  • system.profile.locks.timeAcquiringMicros

  • Cumulative time in microseconds that the operation had to wait toacquire the locks.

timeAcquiringMicros divided byacquireWaitCount gives anapproximate average wait time for the particular lock mode.

  • system.profile.locks.deadlockCount
  • Number of times the operation encountered deadlocks while waitingfor lock acquisitions.

For more information on lock modes, seeWhat type of locking does MongoDB use?.

  • system.profile.storage

New in version 4.2: (Also available starting in 4.0.9)

The system.profile.storage information provides metrics onthe storage engine data and wait time for the operation.

Specific storage metrics are returned only if the values are greaterthan zero.

  • system.profile.storage.data.bytesRead

New in version 4.2: (Also available starting in 4.0.9)

Number of bytes read by the operation from the disk to the cache.

  • system.profile.storage.data.timeReadingMicros

New in version 4.2: (Also available starting in 4.0.9)

Time in microseconds that the operation had to spend to read fromthe disk.

  • system.profile.storage.data.bytesWritten

New in version 4.2: (Also available starting in 4.0.9)

Number of bytes written by the operation from the cache to thedisk.

  • system.profile.storage.data.timeWritingMicros

New in version 4.2: (Also available starting in 4.0.9)

Time in microseconds that the operation had to spend to write tothe disk.

  • system.profile.storage.timeWaitingMicros.cache

New in version 4.2: (Also available starting in 4.0.9)

Time in microseconds that the operation had to wait for space inthe cache.

  • system.profile.storage.timeWaitingMicros.schemaLock

New in version 4.2: (Also available starting in 4.0.9)

Time in microseconds that the operation (if modifying the schema)had to wait to acquire a schema lock.

  • system.profile.storage.timeWaitingMicros.handleLock

New in version 4.2: (Also available starting in 4.0.9)

Time in microseconds that the operation had to wait to acquirethe a lock on the needed data handles.

  • system.profile.nreturned
  • The number of documents returned by the operation.

Note

When MongoDB writes query profile information to the log,the responseLength value is in a fieldnamed reslen.

  • system.profile.millis
  • The time in milliseconds from the perspective of themongod from the beginning of the operation to the end ofthe operation.
  • system.profile.planSummary

New in version 3.4.

A summary of the execution plan.

  • system.profile.execStats

Changed in version 3.0.

A document that contains the execution statistics of the queryoperation. For other operations, the value is an empty document.

The system.profile.execStats presents the statistics as atree; each node provides the statistics for the operation executedduring that stage of the query operation.

Note

The following fields list for execStatsis not meant to be exhaustive as the returned fields vary perstage.

  • system.profile.execStats.stage

New in version 3.0: stage replaces the type field.

The descriptive name for the operation performed as part of thequery execution; e.g.

  1. - <code>COLLSCAN</code> for a collection scan
  2. - <code>IXSCAN</code> for scanning index keys
  3. - <code>FETCH</code> for retrieving documents
  • system.profile.execStats.inputStages

New in version 3.0: inputStages replaces thechildren field.

An array that contains statistics for the operations that are theinput stages of the current stage.

  • system.profile.ts
  • The timestamp of the operation.
  • system.profile.client
  • The IP address or hostname of the client connection where theoperation originates.
  • system.profile.appName

New in version 3.4.

The identifier of the client application which ran the operation. Usethe appName connection string option to set a custom valuefor the appName field.

  • system.profile.allUsers
  • An array of authenticated user information (user name and database)for the session. See also Users.
  • system.profile.user
  • The authenticated user who ran the operation. If the operation wasnot run by an authenticated user, this field’s value is an emptystring.