# Bulk Operations

> Source: https://docs.strapi.io/cms/api/query-engine/bulk-operations

Bulk Operations with the Query Engine API enable you to create, update, delete, and count multiple entries at once using `createMany()`, `updateMany()`, `deleteMany()`, and `count()` methods.

:::caution
In most cases you should not use the Query Engine API and rather use the [Document Service API](/cms/api/document-service).

Only use the Query Engine API if you exactly know what you are doing, for instance if you want to use a lower-level API that directly interacts with unique rows of the database.

Please keep in mind that the Query Engine API is not aware of the most advanced Strapi 5 features like Draft & Publish, Internationalization, Content History, and possibly more.
This also means that the Query Engine API will not be able to use `documentId` and will use `id`, which means it could lead to unattended consequences at the database level or partial or incomplete compatibility with Strapi 5 features. 
:::

:::prerequisites
Before diving deeper into the Query Engine API documentation, it is recommended that you read the following introductions:
- the [backend customization introduction](/cms/backend-customization),
- and the [Content APIs introduction](/cms/api/content-api).
:::

:::caution
To avoid performance issues, bulk operations are not allowed on relations.
:::

## createMany()

Creates multiple entries.

Syntax: `createMany(parameters) => { count: number, ids: id[] }`

### Parameters

| Parameter | Type             | Description         |
| --------- | ---------------- | ------------------- |
| `data`    | Array of objects | Array of input data |

:::caution
* MySQL will only return an array of one id containing the last inserted id, not the entire list.
* Prior to Strapi v4.9.0, `createMany()` only returns the `count`. 
:::

### Example

```js
await strapi.db.query("api::blog.article").createMany({
  data: [
    {
      title: "ABCD",
    },
    {
      title: "EFGH",
    },
  ],
});

// { count: 2 , ids: [1,2]}
```

## updateMany()

Updates multiple entries matching the parameters.

Syntax: `updateMany(parameters) => { count: number }`

### Parameters

| Parameter | Type                                                      | Description                                             |
| --------- | --------------------------------------------------------- | ------------------------------------------------------- |
| `where`   | [`WhereParameter`](/cms/api/query-engine/filtering/) | [Filters](/cms/api/query-engine/filtering/) to use |
| `data`    | Object                                                    | Input data                                              |

### Example

```js
await strapi.db.query("api::shop.article").updateMany({
  where: {
    price: 20,
  },
  data: {
    price: 18,
  },
});

// { count: 42 }
```

## deleteMany()

Deletes multiple entries matching the parameters.

Syntax: `deleteMany(parameters) => { count: number }`

### Parameters

| Parameter | Type                                                      | Description                                             |
| --------- | --------------------------------------------------------- | ------------------------------------------------------- |
| `where`   | [`WhereParameter`](/cms/api/query-engine/filtering/) | [Filters](/cms/api/query-engine/filtering/) to use |

### Example

```js
await strapi.db.query("api::blog.article").deleteMany({
  where: {
    title: {
      $startsWith: "v3",
    },
  },
});

// { count: 42 }
```

## Aggregations

### count()

Counts entries matching the parameters.

Syntax: `count(parameters) => number`

#### Parameters

| Parameter | Type                                                      | Description                                             |
| --------- | --------------------------------------------------------- | ------------------------------------------------------- |
| `where`   | [`WhereParameter`](/cms/api/query-engine/filtering/) | [Filters](/cms/api/query-engine/filtering/) to use |

```js
const count = await strapi.db.query("api::blog.article").count({
  where: {
    title: {
      $startsWith: "v3",
    },
  },
});

// 12
```
