# 核心服务方法使用文档服务 API

> Source: https://strapi.nodejs.cn/cms/migration/v4-to-v5/breaking-changes/core-service-methods-use-document-service

🌐 Core service methods use the Document Service API

在 Strapi 5 中，核心服务方法使用文档服务 API（Document Service API）而不是实体服务 API（Entity Service API），像 `findOne`、`update` 和 `delete` 这样的方法接收的是 `documentId` 而不是 `entityId`。

🌐 In Strapi 5, core service methods use the Document Service API instead of the Entity Service API, with methods like `findOne`, `update`, and `delete` receiving a `documentId` instead of `entityId`.

在 Strapi 5 中，核心服务方法使用文档服务 API，而不是实体服务 API。

🌐 In Strapi 5, core service methods use the Document Service API instead of the Entity Service API.

此页面是[重大更改数据库](/cms/migration/v4-to-v5/breaking-changes)的一部分，提供关于重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的附加说明。

🌐 This page is part of the [breaking changes database](/cms/migration/v4-to-v5/breaking-changes) and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.

- Is this breaking change affecting plugins? Yes
- Is this breaking change automatically handled by a codemod? No

## 重大变更描述 {#breaking-change-description}

🌐 Breaking change description

**在 Strapi v4 中**

核心控制器和 `createCoreService` 工厂默认使用实体服务 API。<br/>例如，像 `find`、`update` 和 `delete` 这样的方法接收一个 `entityId`。

**在 Strapi 5 中**

核心控制器和 `createCoreService` 工厂使用 [文档服务 API](/cms/api/document-service)。<br/>例如，`find`、`update` 和 `delete` 等方法接收一个 `documentId`。

## 迁移 {#migration}

🌐 Migration

本节重新组合了有关引入的重大更改的有用说明和程序。

🌐 This section regroups useful notes and procedures about the introduced breaking change.

### 注意 {#notes}

🌐 Notes

一些核心方法在 Strapi v4 中调用 `super.find(ctx)`，而 `super.find(ctx)` 内部调用实体服务方法，而在 Strapi 5 中，它们调用文档服务 API 方法。这可能导致某些查询不再工作，或者返回的结果与预期略有不同。

🌐 Some core methods are calling `super.find(ctx)` which internally calls entity service methods in Strapi v4, while they call Document Service API methods in Strapi 5. This may result in some queries no longer working, or returning slightly different results from expecting.

以下示例显示了应如何更新代码：

🌐 The following examples show how the code should be updated:

  **在 Strapi v4 中：**

  ```js title="/src/api/my-api-name/services/my-service.js"
  const { createCoreService } = require('@strapi/strapi').factories;

  module.exports = createCoreService('api::address.address', {

    findOne(entityId, params) {
      // customization
      super.findOne(entityId, params);
      
      // or to show a bit more context
      strapi.entityService.findOne(uid, entityId, params);
    },
    
    update(entityId, params) {
      // customization
      super.update(entityId, params);
    },
    
    delete(entityId, params) {
      // customization
      super.delete(entityId, params)
    }

  });
  ```

  **在 Strapi 5 中：**

  ```js title="/src/api/my-api-name/services/my-service.js"
  const { createCoreService } = require('@strapi/strapi').factories;

  module.exports = createCoreService('api::address.address', {

    findOne(documentId, params) {
      // customization
      super.findOne(documentId, params);
      
      // or to show a bit more context
      strapi.documents(uid).findOne(documentId, params);
    },

    update(documentId, params) {
      // customization
      super.update(documentId, params);
    },

    delete(documentId, params) {
      // customization
      super.delete(documentId, params)
    }
  });
  ```

### 手动操作 {#manual-procedure}

🌐 Manual procedure

要更新你的自定义代码：

🌐 To update your custom code:

1. 查找所有带有自定义的 `createCoreService` 调用。
2. 如果 `findOne, delete, update` 的任何函数针对集合类型扩展了核心方法，请按照 [notes](#notes) 中的说明更新它们。

此外，请参考 [Entity Service API 到 Document Service API 的迁移](/cms/migration/v4-to-v5/additional-resources/from-entity-service-to-document-service) 文档。

🌐 Additionally, please refer to the [Entity Service API to Document Service API migration](/cms/migration/v4-to-v5/additional-resources/from-entity-service-to-document-service) documentation.
