Docs Menu
Docs Home
/
MongoDB Manual
/ / /

top

On this page

  • Definition
  • Syntax
  • Event Fields
  • Example
  • Learn More
top

top is an administrative command that returns usage statistics for each collection. You can use top metrics to compare the relative performance of your collections against each other.

Important

The top command must be run against a mongod instance. Running top against a mongos instance returns an error.

For every collection, top returns the amount of time, in microseconds, that each event takes to execute and a count of how many times each event has executed. The time and count metrics reset only after you restart your mongod instance.

Issue the top command against the admin database:

db.runCommand(
{
top: 1
}
)

The top command returns usage statistics for the following event fields:

Field
Description
total
The combination of all readLock and writeLock operations.
readLock
Usage statistics for operations that use read locks. These operations include but are not limited to queries and aggregations.
writeLock
Usage statistics for operations that use write locks. These operations include but are not limited to inserting, updating, and removing documents.
queries
Usage statistics for query operations such as find. The queries.time and queries.count fields also update readLock.time and increment readLock.count.
getmore
Usage statistics for getMore operations. The getmore.time and getmore.count fields also update readLock.time and increment readLock.count.
insert
Usage statistics for insert operations. The insert.time and insert.count fields also update readLock.time and increment readLock.count.
update
Usage statistics for update operations. The update.time and update.count fields also update readLock.time and increment readLock.count.
remove
Usage statistics for delete operations. The remove.time and remove.count fields also update readLock.time and increment readLock.count.
commands

Usage statistics for operations such as aggregations, index creation, and index removal. Depending on the type of command, the commands.time and commands.count fields update the writeLock fields or the readLock fields.

For example, aggregation operations increment readLock.time and readLock.count. Index creation increments writeLock.time and writeLock.count.

The output of the top command resembles the following output:

{
"totals" : {
note: "all times in microseconds",
"records.users" : {
"total" : {
"time" : 305277,
"count" : 2825
},
"readLock" : {
"time" : 305264,
"count" : 2824
},
"writeLock" : {
"time" : 13,
"count" : 1
},
"queries" : {
"time" : 305264,
"count" : 2824
},
"getmore" : {
"time" : 0,
"count" : 0
},
"insert" : {
"time" : 0,
"count" : 0
},
"update" : {
"time" : 0,
"count" : 0
},
"remove" : {
"time" : 0,
"count" : 0
},
"commands" : {
"time" : 0,
"count" : 0
}
}
}

Back

shardConnPoolStats