mongo --host <servername> compact.js
utile quando si prova a risparmia spazio su disco anche se non è sempre detto che funzioni...
This file contains hidden or 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
//V 0.1 | |
// Marco Berri | |
//marcoberri@gmail.com http://tecnicume.blogspot.com | |
function compactCollections(dbName){ | |
var dbToCompact = db.getSisterDB(dbName); | |
dbToCompact.getCollectionNames().forEach(function(cName) { | |
if( cName.indexOf("system") != -1) | |
return; | |
coll = dbToCompact[cName]; | |
print("--------------------") | |
print("collections:" + cName); | |
print("count: " + coll.count()); | |
var storage = coll.stats().storageSize; | |
var size = coll.stats().size; | |
print(" storage: " + storage); | |
print(" size: " + size); | |
dbToCompact.runCommand ( { compact: cName } ); | |
var storagepost = coll.stats().storageSize; | |
var sizepost = coll.stats().size; | |
print(" storagepost: " + storagepost); | |
print(" sizepost: " + sizepost); | |
}); | |
}; | |
listDatabases = db.adminCommand('listDatabases') | |
print("Tot dbs:" + listDatabases.databases.length); | |
for(var i=0; i<listDatabases.databases.length;i++){ | |
print("******************************"); | |
print("Start Compact db:" + listDatabases.databases[i].name); | |
compactCollections(listDatabases.databases[i].name); | |
}; | |
Nessun commento:
Posta un commento