# Memory.getThreadsByResourceId()
[EN] Source: https://mastra.ai/reference/memory/getThreadsByResourceId

The `.getThreadsByResourceId()` function retrieves all threads associated with a specific resource ID from storage. Threads can be sorted by creation or modification time in ascending or descending order.

## Usage Example

```typescript
await memory?.getThreadsByResourceId({ resourceId: "user-123" });
```

## Parameters

<PropertiesTable
  content={[
    {
      name: "resourceId",
      type: "string",
      description: "The ID of the resource whose threads are to be retrieved.",
      isOptional: false,
    },
    {
      name: "orderBy",
      type: "ThreadOrderBy",
      description:
        "Field to sort threads by. Accepts 'createdAt' or 'updatedAt'. Default: 'createdAt'",
      isOptional: true,
    },
    {
      name: "sortDirection",
      type: "ThreadSortDirection",
      description:
        "Sort order direction. Accepts 'ASC' or 'DESC'. Default: 'DESC'",
      isOptional: true,
    },
  ]}
/>

## Returns

<PropertiesTable
  content={[
    {
      name: "StorageThreadType[]",
      type: "Promise",
      description:
        "A promise that resolves to an array of threads associated with the given resource ID.",
    },
  ]}
/>

## Extended usage example

```typescript title="src/test-memory.ts" showLineNumbers copy
import { mastra } from "./mastra";

const agent = mastra.getAgent("agent");
const memory = await agent.getMemory();

const thread = await memory?.getThreadsByResourceId({
  resourceId: "user-123",
  orderBy: "updatedAt",
  sortDirection: "ASC",
});

console.log(thread);
```

### Related

- [Memory Class Reference](/reference/memory/memory-class)
- [getThreadsByResourceIdPaginated](/reference/memory/getThreadsByResourceIdPaginated) - Paginated version
- [Getting Started with Memory](/docs/memory/overview) (Covers threads/resources concept)
- [createThread](/reference/memory/createThread)
- [getThreadById](/reference/memory/getThreadById)


---
title: "Reference: Memory.getThreadsByResourceIdPaginated() | Memory"
description: "Documentation for the `Memory.getThreadsByResourceIdPaginated()` method in Mastra, which retrieves threads associated with a specific resource ID with pagination support."
---