docs/trash/overview.mdx
Trash (also known as soft delete) allows documents to be marked as deleted without being permanently removed. When enabled on a collection, deleted documents will receive a deletedAt timestamp, making it possible to restore them later, view them in a dedicated Trash view, or permanently delete them.
Soft delete is a safer way to manage content lifecycle, giving editors a chance to review and recover documents that may have been deleted by mistake.
To enable soft deleting for a collection, set the trash property to true:
import type { CollectionConfig } from 'payload'
export const Posts: CollectionConfig = {
slug: 'posts',
trash: true,
fields: [
{
name: 'title',
type: 'text',
},
// other fields...
],
}
When enabled, Payload automatically injects a deletedAt field into the collection's schema. This timestamp is set when a document is soft-deleted, and cleared when the document is restored.
Once trash is enabled, the Admin Panel provides a dedicated Trash view for each collection:
/collections/:collectionSlug/trashTrash view shows all documents that have a deletedAt timestampFrom the Trash view, you can:
Use bulk actions to manage trashed documents:
deletedAt timestamp and return documents to their original stateEnter each document's edit view, just like in the main list view. While in the edit view of a trashed document:
When deleting a document from the main collection List View, Payload will soft-delete the document by default. A checkbox in the delete confirmation modal allows users to skip the trash and permanently delete instead.
Soft deletes are fully supported across all Payload APIs: Local, REST, and GraphQL.
The following operations respect and support the trash functionality:
findfindByIDupdateupdateByIDdeletedeleteByIDfindVersionsfindVersionByIDtrash BehaviorPassing trash: true to these operations will include soft-deleted documents in the query results.
To return only soft-deleted documents, you must combine trash: true with a where clause that checks if deletedAt exists.
Return all documents including trashed:
const result = await payload.find({
collection: 'posts',
trash: true,
})
Return only trashed documents:
const result = await payload.find({
collection: 'posts',
trash: true,
where: {
deletedAt: {
exists: true,
},
},
})
Return only non-trashed documents:
const result = await payload.find({
collection: 'posts',
trash: false,
})
Return all documents including trashed:
GET /api/posts?trash=true
Return only trashed documents:
GET /api/posts?trash=true&where[deletedAt][exists]=true
Return only non-trashed documents:
GET /api/posts?trash=false
Return all documents including trashed:
query {
Posts(trash: true) {
docs {
id
deletedAt
}
}
}
Return only trashed documents:
query {
Posts(
trash: true
where: { deletedAt: { exists: true } }
) {
docs {
id
deletedAt
}
}
}
Return only non-trashed documents:
query {
Posts(trash: false) {
docs {
id
deletedAt
}
}
}
All trash-related actions (soft delete, permanent delete, restore) respect the delete access control defined in your collection config.
This means:
You can configure access control to allow some users to trash documents while restricting permanent deletion to admins only. This is useful when you want editors to be able to "delete" content (move to trash) but only allow administrators to permanently remove data.
The delete access control function receives a data argument that contains the document data being set during the operation:
data.deletedAt will be set to a timestampdata will be undefinedThis pattern is similar to how publish access control works with data._status.
import type { CollectionConfig } from 'payload'
export const Posts: CollectionConfig = {
slug: 'posts',
trash: true,
access: {
delete: ({ req: { user }, data }) => {
// Not logged in - no access
if (!user) {
return false
}
// Admins can do anything (trash or permanently delete)
if (user.roles?.includes('admin')) {
return true
}
// Regular users: check what operation they're attempting
// If data.deletedAt is being set, it's a trash operation - allow it
if (data?.deletedAt) {
return true
}
// Otherwise it's a permanent delete - deny for non-admins
return false
},
},
fields: [
// ...
],
}
import type { CollectionConfig } from 'payload'
export const SensitiveData: CollectionConfig = {
slug: 'sensitive-data',
trash: true,
access: {
delete: ({ req: { user } }) => {
// Only allow admins to trash or permanently delete
return Boolean(user?.roles?.includes('admin'))
},
},
fields: [
// ...
],
}
In the Admin Panel, when a user has permission to trash but not permanently delete:
When a document is soft-deleted:
However, versions are still fully visible and accessible from the edit view of a trashed document. You can view the full version history, but must restore the document itself before restoring any individual version.