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

# Session: Storing Entities

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

To store entities inside the **session** object, use `store()` method.

## Syntax

You can pass the following arguments to the `store()` method:

- entity only: Stores the entity in the session, then extracts the ID from the entity or generates a new one if it's not available.

```javascript
session.store(entity, [documentType]);
```

- entity and an id: Stores the entity in a session with given ID.

```javascript
session.store(entity, id);
```

- entity, an id and store options: Stores the entity in a session with given ID, forces concurrency check with given change vector.

```javascript
session.store(entity, id, [options]);
session.store(entity, id, [documentType]);
```

| Parameters | | |
| - | - | - |
| **entity** | object | Entity that will be stored |
| **id** | string | Entity will be stored under this ID, (`null` to generate automatically) |
| **documentType** | class | class used to determine collection of the entity (extracted from entity by default) |
| **options** | object | Options object with the below properties: |
| **changeVector** | string | entity *change vector* used for concurrency checks (`null` to skip check) |
| **documentType** | class | class used to determine collection of the entity (extracted from entity by default) |

| Return value | |
| - | - |
| Promise | A promise resolved once entity obtained an ID and is stored in Unit of Work |

> **Warning:** Asynchronous call {#asynchronous-call}
>
> `store()` method is asynchronous (since it reaches out to server to get a new ID) and returns a `Promise`, so don't forget to use either `await`, `.then()` *before* saving changes.

> **Info:** On collection name when storing object literals {#on-collection-name-when-storing-object-literals}
>
> In order to comfortably use object literals as entities set the function getting collection name based on the content of the object - `store.conventions.findCollectionNameForObjectLiteral()`
>
> ```javascript
> const store = new DocumentStore(urls, database);
> store.conventions.findCollectionNameForObjectLiteral = entity => entity["collection"];
> // ...
> store.initialize();
> ```
>
> This needs to be done before an `initialize()` call on `DocumentStore` instance. If you fail to do so, your entites will land up in *@empty* collection having an *UUID* for an ID.

## Example

```javascript
const employee = new Employee("John", "Doe");

// generate Id automatically
await session.store(employee);

// send all pending operations to server, in this case only `Put` operation
await session.saveChanges();
```

## 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)
- [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)
