Chapter 18. Seeing What Your Application Is Doing

Once you have an application up and running, how do you know what it’s doing? This chapter covers how to figure out what kinds of queries MongoDB is running, how much data is being written, and other details about what it’s actually doing. You’ll learn about:

  • Finding slow operations and killing them

  • Getting and interpreting statistics about your collections and databases

  • Using command-line tools to give you a picture of what MongoDB is doing

Seeing the Current Operations

An easy way to find slow operations is to see what is running. Anything slow is more likely to show up and have been running for longer. It’s not guaranteed, but it’s a good first step to see what might be slowing down an application.

To see the operations that are running, use the db.currentOp() function:

> db.currentOp()
  "inprog": [{
    "type" : "op",
    "host" : "eoinbrazil-laptop-osx:27017",
    "desc" : "conn3",
    "connectionId" : 3,
    "client" : "",
    "appName" : "MongoDB Shell",
    "clientMetadata" : {
        "application" : {
            "name" : "MongoDB Shell"
        "driver" : {
            "name" : "MongoDB Internal Client",
            "version" : "4.2.0"
        "os" : {
            "type" : "Darwin",
            "name" : "Mac OS X",
            "architecture" : "x86_64",
            "version" : "18.7.0"
    "active" : true,
    "currentOpTime" : "2019-09-03T23:25:46.380+0100",
    "opid" : 13594,
    "lsid" : {
        "id" : UUID("63b7df66-ca97-41f4-a245-eba825485147"),
        "uid" : BinData(0,"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
    "secs_running" : NumberLong(0),
    "microsecs_running" ...

Get MongoDB: The Definitive Guide, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.