Recover from Corrupted Data File
When MongoDB reports data-file corruption but the collection file remains available, use PDU to parse readable records from the file.
I. Initialization
1.1 Configure pdu.ini
DISK_PATH=/recovery-input/mongodb/source/collection-1.wt
SOURCE_VERSION=8.0.0
SOURCE_KIND=copy
SOURCE_FROZEN=true
RESMODE=all
EXMODE=bson1.2 Start PDU and Execute Initialization
./pdu
show;
info;II. Specify the Data File in PDU
2.1 Copy the Corrupted Data File
Preserve a copy of the original file and start PDU from a directory outside the source files. Tasks and output are saved in that working directory. Keep compression, encryption and overflow-page dependencies; file size alone does not show how much data can be recovered.
2.2 Probe the Data File
ds probe /recovery-input/mongodb/source/collection-1.wt;Probe results identify the physical source and parseable ranges. They are not a completed recovery and do not prove collection identity.
III. Parse the Data File
ds idx;
ds idx status;
ds unload all;
ds log;Single-file all mode exports parseable physical versions, which may include duplicate _id values. Collection ownership stays unknown when the file-to-collection relationship cannot be confirmed. PDU does not automatically deduplicate records or fill missing fields.
IV. Handling External Large Values
Large documents may depend on overflow pages. Directory and declared logical-extent paths can read dependencies through known mappings. An unmapped image cannot locate overflow by guessed addresses. Retain original reasons for missing pages and broken chains.
See the directory-map, file-range and image recovery procedure.
Output Files
Collection data is exported as BSON files or Canonical Extended JSON line files. Recovery commands generate offline candidate data without writing to the target database. Native records retain sources, success, failure, unresolved dependencies, original errors and checkpoints.
After export, record the native success and failure counts, unresolved dependencies and original errors reported by PDU, and retain the checkpoint. Resume uses native records and file metadata such as existence and size without rereading exported data.
Common Issues
- Mismatched file type or version: retain identification results without forcing another version profile.
- Missing source pages or overflow: retain unresolved reasons without replacing missing content with zeros.
- An unfinished output unit remains. Use ds resolve discard-active only after deciding to abandon that unit. The command does not delete source files.