Skip to content

Instantly share code, notes, and snippets.

View jpasichnyk's full-sized avatar

Jesse Pasichnyk jpasichnyk

  • GeoRiot
  • Seattle, WA
View GitHub Profile
@BlakeGardner
BlakeGardner / compact.js
Last active February 19, 2024 16:55
Compact all collections inside of a MongoDB database
// This script loops though the list of collection names in a MongoDB and runs the compact operation on them
// Simply paste this into the Mongo shell
use testDbName;
db.getCollectionNames().forEach(function (collectionName) {
print('Compacting: ' + collectionName);
db.runCommand({ compact: collectionName });
});