doctrine/mongodb-odm-softdelete
Adds soft delete support to Doctrine MongoDB ODM. Mark documents as deleted without removing them, with automatic filtering of deleted records from queries and options to restore or include trashed documents. Integrates cleanly with ODM repositories and event system.
isDeleted, deletedAt fields, lifecycle callbacks).$and with deletedAt: null) for efficient filtering, avoiding full-table scans.deletedAt field per document).@SoftDeleteable).deletedAt) could return soft-deleted records, leading to data leaks.deletedAt field to all relevant collections, which may need backward-compatible migration strategies.deletedAt updates aren’t atomic (though Doctrine ODM typically handles this).$redact) that could avoid ODM dependency?mongodb extension).deletedAt field (DateTime) to all relevant collections via migration.use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/** @MongoDB\Document */
class User {
/** @MongoDB\Field(type="date") */
public $deletedAt;
}
@SoftDeleteable and configure deletedAt field.use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/** @MongoDB\SoftDeleteable(fieldName="deletedAt") */
class User { ... }
find() or createQueryBuilder() with soft-delete filters.$qb = $this->createQueryBuilder('u')
->where('u.deletedAt = null');
softDelete($user) instead of remove($user)).$dm->softDelete($user); // Sets deletedAt to now()
1.3.x vs. 2.0+).mongodb library).deletedAt field if needed (e.g., via migration).deletedAt).deletedAt updates (potential abuse).deletedAt is indexed to avoid performance degradation on large collections.
/** @MongoDB\Index(keys={"deletedAt"="asc"}) */
explain() analysis.$collection->createIndex(['deletedAt' => 1], ['expireAfterSeconds' => 2592000]); // 30 days
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Query misses soft-delete filter | Data leaks (deleted records returned) | Automated tests for all read paths. |
deletedAt field not indexed |
Slow queries on large collections | Add index during migration. |
Race condition in deletedAt update |
Inconsistent soft-delete state | Use ODM’s built-in atomic updates. |
| Package incompatibility | Breaks on ODM upgrade | Fork or switch to maintained alternative. |
| Storage bloat from retained records | High MongoDB storage costs | Implement TTL indexes for old entries. |
softDelete()").How can I help you explore Laravel packages today?