Created
July 17, 2016 20:53
-
-
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
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
"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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should bring db connection inside this gist