Question (chapter 3): Difference between WRITE and COMMAND log components

As part of the Chapter 3 Lab: Building an Index in the Foreground in Production, I was studying the logs.

I want to know the difference (and any relationship) with the log components COMMAND (messages related to database commands) and WRITE (messages related to write operations, such as update commands) I am seeing. The log messages look similar (not same).

For example:

Tue Mar 10 10:25:57.214 I **WRITE** [conn49] update m312.employees query: { _id: ObjectId('5e6764727f5fc68f7b645caf') } planSummary: IDHACK update: { $inc: { count: 1 } } keysExamined:1 docsExamined:1 nMatched:1 nModified:1 numYields:0 locks:{Global: { acquireCount: { r: 2, w: 2 } }, Database: { acquireCount: { w: 2 }, acquireWaitCount: { w: 1 }, timeAcquiringMicros: { w: 8943248 } }, Collection: { acquireCount: { w: 1 } }, Metadata: { acquireCount: { w: 1 } }, oplog: { acquireCount: { w: 1 } } } (0hr 0min 8secs 958ms) 8,958ms

Tue Mar 10 10:25:57.214 I **COMMAND** [conn49] command m312.$cmd command: update { update: "employees", ordered: true, updates: [ { q: { _id: ObjectId('5e6764727f5fc68f7b645caf') }, u: { $inc: { count: 1 } }, multi: false, upsert: false } ] } numYields:0 reslen:119 locks:{ Global: { acquireCount: { r: 2, w: 2 } }, Database: { acquireCount: { w: 2 }, acquireWaitcount: { w: 1 }, timeAcquiringMicros: { w: 8943248 } }, Collection: { acquireCount: { w: 1 } }, Metadata: { acquireCount{ w: 1 } }, oplog: { acquireCount: { w: 1 } } } protocol:op_query (0hr 0min 8secs 958ms) 8,958ms

Thank you,

Prasad.

I would say that they are complimentary.

WRITE shows:

  1. the planSummary whether it used an index, i.e. the plan stage (IXSCAN, IDHACK etc)
  2. some key Execution Stats with regards keys and docs examined
  3. the WriteResult with regards no of docs matched and modified

COMMAND shows:

  1. some of the update (or bulk update) options - multi, upsert, ordered
  2. the reponseLength (reslen)

Both shows:

  1. the query
  2. lock stats
  3. execution time
1 Like

Hi @007_jb / @Prasad_45636

You might find this documentation page on the various log components useful. It expands on what exactly each of those mean, so for WRITE messages, it would typically refer to update commands. In the case of COMMAND messages, these refer to DB commands such as count .

If you ran a query with a count command together, you could see two lines in your log, one line with COMMAND plus the actual query and then a second QUERY plus the actual query. I wanted to point on this example specifically to highlight that you may see things repeated in the log but that these repetitions are present because in the database these log lines represent different operations.

Hopefully this helps clarify how MongoDB logs and the log message components.

Kindest regards,
Eoin

2 Likes

Thanks for sharing @brazileoin :slight_smile: . I’m actually well aware of that documentation and the behaviour, I just didn’t mention it because I believe that’s where @Prasad_45636 got the descriptions above from.