Recover Updated Records (Historical Candidates)
When a MongoDB collection is accidentally updated, use PDU to scan retained historical sources and export candidate pre-update data. The following sections describe configuration, scanning and export in detail.
Comparison with Deleted Records Recovery
| Recovery Type | Command | Exported Content |
|---|---|---|
| DELETE recovery | RESTYPE=delete; restore | Retained pre-delete candidates |
| UPDATE recovery | RESTYPE=update; restore | Retained pre-update candidates |
I. Initialization
1.1 Preserve the Data Files and Historical Sources
Preserve copies of history store, pre-images and oplog that already exist at the incident. History-store values may have been reclaimed, and pre-images may have been disabled or expired. Old values that were not retained cannot be recreated.
1.2 Configure pdu.ini
MONGODBDATA=/recovery-input/mongodb/source/dbpath1.3 Start PDU and Execute Initialization
./pdu
param sourceversion 8.0.0;
param sourcekind copy;
param sourcefrozen true;
b;
ds catalog status;
\l;Review collection bindings, historical sources and unresolved dependencies in catalog records. Create a new task for old catalog records rather than automatically upgrading source identity.
II. Set Recovery Type
Select update history with param restype update;, keeping the recovery mode set to history.
param resmode history;
param restype update;III. Scan Historical Data
3.1 Navigate to the Target Collection
use appdb;
\dt;
\d orders;Use the collection name resolved by the catalog. For database-wide scanning, specify the database with db database_name.
3.2 Execute the Scan Command
param resmode history;
param restype update;
scan appdb.orders;
# Or scan the selected database:
scan db appdb;3.3 Understanding the Scan Output
Review sources, candidate versions and unresolved reasons in native records. Collection history, history store and pre-images retain separate records; their candidate counts are not a unique business-record count.
ds catalog status;
ds batch status;
ds batch log;IV. Restore Data
Use restore to export offline candidates for the target collection. The command does not connect to a running MongoDB server or automatically update a target collection.
restore appdb.orders;
# Or export candidates for the selected database:
restore db appdb;4.1 Restore All Updated Records
param restype update;
restore db appdb;4.2 Filter by Operation Range
When attributable pre-images and oplog remain available, limit the range by operation timestamp. operationfrom is inclusive and operationbefore is exclusive. Both use SECONDS:INCREMENT, not a business Date field or incident wall-clock time.
param operationfrom 1700000000:1;
param operationbefore 1700000010:1;
ds preimage scan appdb.orders update;
ds preimage unload appdb.orders update;param operationfrom none;
param operationbefore none;V. Using the Recovered Data
Determine how candidates will be used from task records, collection identity and business rules. To compare old versions, import into a user-designated isolated collection and select the applicable version. Do not automatically deduplicate by _id or overwrite a production collection with old values.
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
- Missing history store: retain the missing dependency; a current export is not accidental-operation recovery.
- Missing MODIFY base or intermediate versions: retain unresolved reasons without generating guessed values.
- Unclear pre-image attribution or transaction commit: retain old values and evidence without forcing classification.