from pymongo import MongoClient mongo = MongoClient("mongodb+srv://admin:PASSWORD@staging.mongodb.staging.oonum.io/admin?ssl=false&retryWrites=true&serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&authMechanism=SCRAM-SHA-256&w=majority") # mongo["auth"].command({"compact": "Orgs", "force": True}) mongo["database"].command({"compact": "collection", "force": True}) # Mongo 4.4 can compact without blocking, older versions block IO during compaction.