mirror of
				https://github.com/Mastermindzh/examples.git
				synced 2025-11-04 09:18:13 +01:00 
			
		
		
		
	function to return all indexes on all databases
This commit is contained in:
		
							
								
								
									
										14
									
								
								mongo/get-indexes-on-all-databases.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								mongo/get-indexes-on-all-databases.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
db = db.getSiblingDB("admin");
 | 
			
		||||
dbs = db.runCommand({ listDatabases: 1 }).databases;
 | 
			
		||||
 | 
			
		||||
var indexList = {};
 | 
			
		||||
 | 
			
		||||
dbs.forEach(function (database) {
 | 
			
		||||
  db = db.getSiblingDB(database.name);
 | 
			
		||||
  db.getCollectionNames().forEach(function (collection) {
 | 
			
		||||
    indexes = db[collection].getIndexes();
 | 
			
		||||
    indexList[`${database.name}/${collection}`] = indexes;
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
printjson(indexList);
 | 
			
		||||
		Reference in New Issue
	
	Block a user