---
title: "Increment Next Identity Operation"
url: "https://docs.ravendb.net/6.2/client-api/operations/maintenance/identities/increment-next-identity"
version: "6.2"
language: "php"
---

# Increment Next Identity Operation

> Client language: PHP. Also available for [C#](https://docs.ravendb.net/6.2/client-api/operations/maintenance/identities/increment-next-identity.md), [Python](https://docs.ravendb.net/6.2/client-api/operations/maintenance/identities/increment-next-identity.python.md), [Node.js](https://docs.ravendb.net/6.2/client-api/operations/maintenance/identities/increment-next-identity.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - Use `NextIdentityForOperation` to increment the latest identity value set on the server for the specified collection in the database.
>
> - The next document that will be created using an identity for the collection will receive the consecutive integer value.
>
> - In this page:
>
>   - [Increment the next identity value](#increment-the-next-identity-value)
>   - [Syntax](#syntax)

## Increment the next identity value

```php
// Create a document with an identity ID:
// ======================================

$session = $store->openSession();
try {
  // Pass a collection name that ends with a pipe '|' to create an identity ID
  $company = new Company();
  $company->setName("RavenDB");
  $session->store($company, "companies|");
  $session->saveChanges();
  // => Document "companies/1" will be created
} finally {
  $session->close();
}

// Increment the identity value on the server:
// ===========================================

// Define the next identity operation
// Pass the collection name (can be with or without a pipe)
$nextIdentityOp = new NextIdentityForOperation("companies|");

// Execute the operation by passing it to Maintenance.Send
// The latest value will be incremented to "2"
// and the next document created with an identity will be assigned "3"
$incrementedValue = $store->maintenance()->send($nextIdentityOp);

// Create another document with an identity ID:
// ============================================

$session = $store->openSession();
try {
  $company = new Company();
  $company->setName("RavenDB");
  $session->store($company, "companies|");
  $session->saveChanges();
  // => Document "companies/3" will be created
} finally {
  $session->close();
}
```

## Syntax

```php
NextIdentityForOperation(?string $name);
```

| Parameter | Type | Description |
| - | - | - |
| **$name** | `?string` | The name of a collection to create an ID for |

## See also

- [Working with Document Identifiers](https://docs.ravendb.net/6.2/client-api/document-identifiers/working-with-document-identifiers.md)
- [Global ID Generation Conventions](https://docs.ravendb.net/6.2/client-api/configuration/identifier-generation/global.md)
- [Type-specific ID Generation Conventions](https://docs.ravendb.net/6.2/client-api/configuration/identifier-generation/type-specific.md)
- [Document Identifier Generation](https://docs.ravendb.net/6.2/server/kb/document-identifier-generation.md)
- [What are operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.php.md)
- [Get identities](https://docs.ravendb.net/6.2/client-api/operations/maintenance/identities/get-identities.php.md)
- [Seed identity](https://docs.ravendb.net/6.2/client-api/operations/maintenance/identities/seed-identity.php.md)
