see currently running background indexing jobs (MongoDB)

Posted on

Question :

In mongodb.log I see

2016-03-31T12:44:11.003+0200 I -        [conn58191]   Index Build (background): 14396400/17648149 81%
2016-03-31T12:44:14.018+0200 I -        [conn58191]   Index Build (background): 14414100/17648154 81%
2016-03-31T12:44:17.008+0200 I -        [conn58191]   Index Build (background): 14439300/17648155 81%
2016-03-31T12:44:20.009+0200 I -        [conn58191]   Index Build (background): 14467800/17648159 81%
2016-03-31T12:44:23.003+0200 I -        [conn58191]   Index Build (background): 14492700/17648161 82%
2016-03-31T12:44:26.003+0200 I -        [conn58191]   Index Build (background): 14520500/17648166 82%
2016-03-31T12:44:29.003+0200 I -        [conn58191]   Index Build (background): 14551500/17648166 82%
2016-03-31T12:44:32.012+0200 I -        [conn58191]   Index Build (background): 14571300/17648170 82%
2016-03-31T12:44:35.001+0200 I -        [conn58191]   Index Build (background): 14584100/17648171 82%
2016-03-31T12:44:38.008+0200 I -        [conn58191]   Index Build (background): 14600100/17648174 82%
2016-03-31T12:44:41.004+0200 I -        [conn58191]   Index Build (background): 14619700/17648178 82%
2016-03-31T12:44:44.005+0200 I -        [conn58191]   Index Build (background): 14641700/17648184 82%
2016-03-31T12:44:47.094+0200 I -        [conn58191]   Index Build (background): 14665900/17648185 83%
2016-03-31T12:44:50.004+0200 I -        [conn58191]   Index Build (background): 14685600/17648188 83%
2016-03-31T12:44:53.002+0200 I -        [conn58191]   Index Build (background): 14700800/17648188 83%

I wish to see this in mongo shell. I also wish to see which index.

I googled and found

db.currentOp(
    {
      $or: [
        { op: "query", "query.createIndexes": { $exists: true } },
        { op: "insert", ns: /.system.indexesb/ }
      ]
    }
)

But this query gives only

{ "inprog" : [ ], "ok" : 1 }

I wish to see all details.

Answer :

I have noticed the same thing in last week. Sometimes, the mongo shell returns any empty array:

  1. Try running the currentOp() many times to get the progress.
  2. Use use db command and then perform db.currentOp()

I find this command helps to show index progress:

db.currentOp().inprog.map(a => a.msg)
[
    undefined,
    undefined,
    undefined,
    undefined,
    undefined,
    undefined,
    "Index Build: scanning collection Index Build: scanning collection: 16448156/54469342 30%",
    undefined,
    undefined
]

Leave a Reply

Your email address will not be published. Required fields are marked *