Handwriting-- mongo index building
Remember: database operation should be cautious, it is recommended to do a good job in the operation of failed operations, but also in a timely manner.
Because of the index established this time, the background creates it, and finds corresponding measures, such as: the creation of the index can be interrupted in time.
Index creation operation: the following operations have been done in tables with tens of millions of data
1. Check whether the collection has an index: db.getCollection ("_ TEMPLATE_TASK_TIME_HISTORY") .getIndexes () 2. Total index size: db.getCollection ("_ TEMPLATE_TASK_TIME_HISTORY") .totalIndexSize () 3. Delete index (execute in the background if you can): db.getCollection ("_ TEMPLATE_TASK_TIME_HISTORY"). DropIndex ({"countTime": 1}, {background:true}) 4, create the index (be sure to execute in the background, otherwise lock the library The reason is that a large number of reads and writes will mess up the data during indexing): db.getCollection ("_ TEMPLATE_TASK_TIME_HISTORY"). DropIndex ({"countTime": 1}, {background:true}) 5. Check the progress of index creation: db.currentOp (). Inprog.forEach (function (op) {if (op.msg) print (op.msg)}) how to interrupt the progress of the index being created: https://cloud.tencent.com/developer/article/1502344