Created
May 26, 2021 15:41
-
-
Save luckydev/f9d28af6ff390d57d582799d2dd73f06 to your computer and use it in GitHub Desktop.
Create MongoDB index in background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//query to create an index in background. won't stop current reads/writes on the collection | |
db.collection.createIndex( { 'key1': 1 }, { background: true } ) | |
//query to create a compount index in background. won't stop current reads/writes on the collection | |
db.collection.createIndex( { 'key1': 1, 'key2': 1 }, { background: true } ) | |
//to check the progress of indexing operation | |
db.currentOp(true).inprog.forEach(function(op){ if(op.msg!==undefined) print(op.msg) }) | |
//to kill the indexing operation, just in case. | |
db.killOp(<opid of the query to kill>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment