---
title: "Session: Deleting Entities"
url: "https://docs.ravendb.net/6.2/client-api/session/deleting-entities"
version: "6.2"
language: "nodejs"
---

# Session: Deleting Entities

> Client language: Node.js. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/deleting-entities.md), [Java](https://docs.ravendb.net/6.2/client-api/session/deleting-entities.java.md), [Python](https://docs.ravendb.net/6.2/client-api/session/deleting-entities.python.md), [PHP](https://docs.ravendb.net/6.2/client-api/session/deleting-entities.php.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."

Entities can be marked for deletion by using the `delete()` method, but will *not* be removed from the server until `saveChanges()` is called.

## Syntax

```javascript
await session.delete(entity);

await session.delete(id);

await session.delete(id, [changeVector]);
```

| Parameters | | |
| - | - | - |
| **entity** | `object` | Instance of the entity to delete |
| **id** | `string` | The entity ID |
| **changeVector** | `string` | a change vector to use for concurrency checks |

## Example I

```javascript
const employee = await session.load("employees/1");

await session.delete(employee);
await session.saveChanges();
```

> **Note:** Concurrency on Delete {#concurrency-on-delete}
>
> If `useOptimisticConcurrency` is set to *true* (default *false*), the `delete()` method will use loaded *employees/1* change vector for concurrency check and might throw `ConcurrencyException`.

## Example II

```javascript
await session.delete("employees/1");
await session.saveChanges();
```

> **Note:** Concurrency on Delete {#concurrency-on-delete-1}
>
> In this example, the `delete()` method will not do any change vector based concurrency checks because the change vector for *employees/1* is unknown.

> **Info:** Information {#information}
>
> If entity is **not** tracked by session, then executing
>
> ```javascript
> await session.delete("employees/1");
> ```
>
> is equal to doing
>
> ```javascript
> await session.advanced.defer(new DeleteCommandData("employees/1", null));
> ```
>
> > **Note:** Change Vector in DeleteCommandData {#change-vector-in-deletecommanddata}
> >
> > In this sample the change vector is null - this means that there will be no concurrency checks. A non-null and valid change vector value will trigger a concurrency check.
>
> You can read more about defer operations [here](https://docs.ravendb.net/6.2/client-api/session/how-to/defer-operations.nodejs.md).

## See also

- [What is a Session and How Does it Work](https://docs.ravendb.net/6.2/client-api/session/what-is-a-session-and-how-does-it-work.nodejs.md)
- [Opening a Session](https://docs.ravendb.net/6.2/client-api/session/opening-a-session.nodejs.md)
- [Loading Entities](https://docs.ravendb.net/6.2/client-api/session/loading-entities.nodejs.md)
- [Saving Changes](https://docs.ravendb.net/6.2/client-api/session/saving-changes.nodejs.md)
- [How To: Enable Optimistic Concurrency](https://docs.ravendb.net/6.2/client-api/session/configuration/how-to-enable-optimistic-concurrency.nodejs.md)
- [Query Overview](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.nodejs.md)
- [Basics](https://docs.ravendb.net/6.2/indexes/querying/query-index.nodejs.md)
- [What is a Document Store](https://docs.ravendb.net/6.2/client-api/what-is-a-document-store.nodejs.md)
