Document Service API: Selecting fields
Page summary:Use the
fieldsparameter in Document Service API queries to select specific fields to return with your results, reducing data payload acrossfindOne(),findMany(),create(),update(),delete(),publish(), and other document operations.
By default the Document Service API returns all the fields of a document but does not populate any fields. This page describes how to use the fields parameter to return only specific fields with the query results.
You can also use the populate parameter to populate relations, media fields, components, or dynamic zones (see the populate parameter documentation).
Though it's recommended to target entries by their documentId in Strapi 5, entries might still have an id field, and you will see it in the returned response. This should ease your transition from Strapi 4. Please refer to the breaking change entry for more details.
Select fields with findOne() queries
strapi.documents("api::restaurant.restaurant").findOne()Select fields with findOne()
Select specific fields to return when finding a document by documentId.
Select fields with findFirst() queries
strapi.documents("api::restaurant.restaurant").findFirst()Select fields with findFirst()
Select specific fields to return when finding the first matching document.
Select fields with findMany() queries
strapi.documents("api::restaurant.restaurant").findMany()Select fields with findMany()
Select specific fields to return when finding multiple documents.
Select fields with create() queries
strapi.documents("api::restaurant.restaurant").create()Select fields with create()
Select specific fields to return when creating a new document.
Select fields with update() queries
strapi.documents("api::restaurant.restaurant").update()Select fields with update()
Select specific fields to return when updating a document.
Select fields with delete() queries
strapi.documents("api::restaurant.restaurant").delete()Select fields with delete()
Select specific fields to return when deleting a document.
Select fields with publish() queries
strapi.documents("api::restaurant.restaurant").publish()Select fields with publish()
Select specific fields to return when publishing a document.
Select fields with unpublish() queries
strapi.documents("api::restaurant.restaurant").unpublish()Select fields with unpublish()
Select specific fields to return when unpublishing a document.
Select fields with discardDraft() queries
strapi.documents("api::restaurant.restaurant").discardDraft()Select fields with discardDraft()
Select specific fields to return when discarding a draft document.