# Collection: get() method

> The get() method of the Collection interface resolves with an entry and its value, or undefined when there is none.

The **`get()`** method of the [`Collection`](/docs/room/collection) interface resolves with an entry and its value, or `undefined` when the collection has no entry with that ID.

## Syntax

```ts
get(id)
get<T>(id)
```

### Parameters

`id`
: The entry's ID.

### Return value

A `Promise` that resolves with the entry, or `undefined`. The entry is an object with these properties:

`id`
: The entry's ID.

`value`
: Its value, JSON or a `Uint8Array`. The type parameter `T` types it, without checking it.

`meta`
: Its flat `meta`, `{}` when it has none.

`score`
: Its score, or `null`.

`owner`
: The player who owns it, or `null`.

`version`
: Its version, which goes up on every write.

`created` and `updated`
: When it was created and last written, in wall-clock milliseconds.

### Exceptions

The promise rejects with a [`DataError`](/docs/room/data-error), such as `E_UNKNOWN` when the collection isn't declared.

## Description

A `get()` within 5 seconds of the room's last read or write of the same entry is answered from memory, except that the first `get()` after the room's own [`put()`](/docs/room/collection/put) of it reads it again, since the data service sets its times.

## Examples

### Loading the level a room was created for

```ts
// play-level.ts
import { defineRoom, defineSchema, entity, json } from "@irtio/room";

const Level = entity("level", { tiles: json<number[]>([]) });

export default defineRoom({
  schema: defineSchema({ state: Level }),
  async onCreate(room) {
    const id = (room.meta as { level?: string } | null)?.level;
    const level = id ? await room.collection("levels").get<{ tiles: number[] }>(id) : undefined;
    room.state.tiles = level?.value.tiles ?? [];
  },
});
```

## See also

- [`Collection.list()`](/docs/room/collection/list)
- [The cache in the room](/docs/room/guides/player-data#the-cache-in-the-room)
