MongoDB Indexes

?
R
Bash

Syntax for mongo shell to create indexes and view background progress of the index creation

1# Create an index in background mode
2db.getCollection("elements").createIndex({"deletedAt" :1}, { background: true })
3db.getCollection("elements").getIndexes()
4
5# View stats of the background process
6db.currentOp(true)
7db.currentOp().inprog.forEach(function(op){ if(op.msg) print(op.msg) })
8db.currentOp({"command.createIndexes": { $exists : true } })
9
10# Get Indexes and ClearIndexes
11db.getCollection("mapped-apis").getIndexes();
12db.getCollection("mapped-apis").dropIndex("name_1");

Created on 2/2/2019