Skip to content

Instantly share code, notes, and snippets.

@spiritinlife
Created July 17, 2016 20:53
Show Gist options
  • Save spiritinlife/eb73a56ed18107ab4440124f9f4838b5 to your computer and use it in GitHub Desktop.
Save spiritinlife/eb73a56ed18107ab4440124f9f4838b5 to your computer and use it in GitHub Desktop.
Mongojs get all database indexes and map them to their collection in an object
"use strict";
var db = require('../db');
var indexes = {};
db.getCollectionNames(function (err, collections) {
for (var i=0; i<collections.length; i++) {
indexes[collections[i]] = [];
(function (i) {
db.collection(collections[i]).getIndexes(function (err, collectionIndexes) {
for (var j=0; j<collectionIndexes.length; j++) {
indexes[collections[i]].push(collectionIndexes[j].name);
}
})
})(i);
}
});
module.exports = indexes;
@spiritinlife
Copy link
Author

Should bring db connection inside this gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment