dataiotech Labs
Scripts Library/mongodb/#94
Script #94
mongodb
Data Qualityread-onlyMin Version: 4.0

Find Oversized Documents in MongoDB

Ranks the largest documents in a collection in bytes. Catches documents approaching the 16 MB limit and schema anti-patterns.

#document-size#16mb-limit#schema
mongodb · javascript
db.orders.aggregate([
  { $project: { size: { $bsonSize: "$$ROOT" } } },
  { $sort: { size: -1 } },
  { $limit: 10 }
], { allowDiskUse: true });
Operational Notes & Remediation Guidance

MongoDB BSON document limit is 16MB. Large documents near this threshold must be refactored or stored in GridFS.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 4.0).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.

Engineering Triad: Related Runbooks & Incident Response

Which production incidents and emergency drills execute this script as a diagnosis step?

Runbook Library (63)
Proactive Maintenance & Health Check: This script is not tied to an active incident alert; it is intended for scheduled maintenance, capacity planning, and routine DBA audits.