---
title: "Put Document Command"
url: "https://docs.ravendb.net/6.2/client-api/commands/documents/put"
version: "6.2"
language: "php"
---

# Put Document Command

> Client language: PHP. Also available for [C#](https://docs.ravendb.net/6.2/client-api/commands/documents/put.md), [Java](https://docs.ravendb.net/6.2/client-api/commands/documents/put.java.md), [Python](https://docs.ravendb.net/6.2/client-api/commands/documents/put.python.md), [Node.js](https://docs.ravendb.net/6.2/client-api/commands/documents/put.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 `PutDocumentCommand` to insert a document to the database or update an existing document.
>
> - In this page:
>
>   - [Example](#example)
>   - [Syntax](#syntax)

## Example

```php
// Create a new document
$doc = new Category();
$doc->setName("My category");
$doc->setDescription("My category description");

// Create metadata on the document
$docInfo = new DocumentInfo();
$docInfo->setCollection("Categories");

// Convert your entity to a BlittableJsonReaderObject
$jsonDoc = $session->advanced()->getEntityToJson()->convertEntityToJson($doc, $docInfo);

// The Put command (parameters are document ID, changeVector check is null, the document to store)
$command = new PutDocumentCommand("categories/999", null, $jsonDoc);
// RequestExecutor sends the command to the server
$session->advanced()->getRequestExecutor()->execute($command);
```

## Syntax

```php
PutDocumentCommand(string $idOrCopy, ?string $changeVector, array $document);
```

| Parameters | Type | Description |
| - | - | - |
| **idOrCopy** | `string` | Unique ID under which document will be stored |
| **changeVector** | `string` (optional) | Entity changeVector, used for concurrency checks (`None` to skip check) |
| **document** | `array` | The document to store |

## See also

- [Get document](https://docs.ravendb.net/6.2/client-api/commands/documents/get.php.md)
- [Delete document](https://docs.ravendb.net/6.2/client-api/commands/documents/delete.php.md)
- [Send multiple commands using a batch](https://docs.ravendb.net/6.2/client-api/commands/batches/how-to-send-multiple-commands-using-a-batch.md)
