DEV Community

Cover image for Understanding Strapi 5's Document Service API
Theodore Kelechukwu Onyejiaku
Theodore Kelechukwu Onyejiaku

Posted on Originally published at mystite.com

Understanding Strapi 5's Document Service API

Server racks in a data center

Understanding Strapi 5's Document Service API

Strapi 5 replaced the Entity Service with the Document Service API. It works with documents — identified by a stable documentId — rather than raw database rows.

The basics

const blogs = await strapi.documents('api::blog.blog').findMany({
  filters: { title: { $containsi: 'strapi' } },
  populate: ['tags'],
});
Enter fullscreen mode Exit fullscreen mode

Common methods

Method Purpose
findMany List documents
findOne Get one by documentId
create Create a document
update Update by documentId
delete Remove a document
publish / unpublish Manage draft & publish

Why documentId matters

A document can have several versions (draft, published, one per locale). The documentId stays the same across all of them, so relations and URLs stay stable.

Tip

Use the Document Service inside your plugin services, and keep controllers thin. It makes your logic reusable from lifecycles and cron jobs.

Top comments (0)