简体   繁体   English

如何通过shell查看MongoDB的索引创建进度

[英]How to check index creation progress in MongoDB via shell

On a large collection of billions records in MongoDB an index creation is submitted.在 MongoDB 中的数十亿条记录的大型集合中,提交了索引创建。 I run db.getCollection('mycollection').aggregate([ { "$indexStats": { } } ] ) and i get result containing property building:true .我运行db.getCollection('mycollection').aggregate([ { "$indexStats": { } } ] )并得到包含属性building:true的结果。

Question: How could I check the progress of the index building eg percentage complete?问题:如何检查索引构建的进度,例如完成百分比?

db.currentOp https://www.mongodb.com/docs/manual/reference/command/currentOp/ db.currentOp https://www.mongodb.com/docs/manual/reference/command/currentOp/

It returns a lot, but you are interested in a document where command has createIndexes or msg string contains "Index Build".它返回很多,但您对command具有createIndexesmsg字符串包含“Index Build”的文档感兴趣。

If the output is too noisy, you can filter running adminCommand directly:如果 output 太吵,可以直接过滤运行 adminCommand:

db.adminCommand(
    {
      currentOp: true,
      $or: [
        { op: "command", "command.createIndexes": { $exists: true }  },
        { op: "none", "msg" : /^Index Build/ }
      ]
    }
)

The field progress of the document reveals done and total .文档的现场progress显示donetotal You can do the math.你可以算一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM