Skip to content

Instantly share code, notes, and snippets.

View sar-joshi's full-sized avatar

Sar J sar-joshi

View GitHub Profile
print("Database,Collection,Index Name,Is Unique,Is Sparse,TTL (seconds),Fields");
db.getMongo().getDBs().databases.forEach(function(database) {
// print("\nDatabase:", database.name);
if (database.name !== 'admin' && database.name !== 'local' && database.name !== 'config') {
var dbs = db.getSiblingDB(database.name);
dbs.getCollectionNames().forEach(function(collName) {
// print("\collName:", collName);
// Create an object to store all index information
var clusterIndexes = {};
db.getMongo().getDBs().databases.forEach(function(database) {
if (database.name !== 'admin' && database.name !== 'local' && database.name !== 'config') {
clusterIndexes[database.name] = {};
var dbs = db.getSiblingDB(database.name);
dbs.getCollectionNames().forEach(function(collName) {
clusterIndexes[database.name][collName] = db.getCollection(collName).getIndexes();