> For the complete documentation index, see [llms.txt](https://suhantudor.gitbook.io/crud-node/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://suhantudor.gitbook.io/crud-node/reference/api-reference/groupbydocuments-4.md).

# fetchAll 🆕

Fetch documents filtered by statement

{% hint style="info" %}

```typescript
Throws `errorNoCriteriaProvided` if props are empty.
```

{% endhint %}

**Signature**

{% tabs %}
{% tab title="MySQL" %}

```javascript
fetchAll(session: MySQLSession, sort?: Sort, filter?: {
        props: Partial<IDocument<S>>;
        join: 'OR' | 'AND';
    }, filterCriteria?: FilterCriteria): Promise<Array<IDocument<S>>>;
```

{% endtab %}

{% tab title="MySQLX" %}

```javascript
fetchAll(session: MySQLXSession, sort?: Sort, filter?: {
        props: Partial<IDocument<S>>;
        join: 'OR' | 'AND';
    }): Promise<Array<IDocument<S>>>;
```

{% endtab %}
{% endtabs %}

**Example**

{% tabs %}
{% tab title="MySQL" %}

```javascript
// employeeRouter.{ts|js}
import { OffsetPagination, SortBy } from 'crud-node';
import { employeeController } from './employeeController';
import { EmployeeProps } from './schemas/employee';

const transacted = true;

await db.usingSession(async (session) => {
  const sort = SortBy().asc(EmployeeProps.createdAt).toCriteria();
  const data = await employeeController.fetchAll(session, sort, {
    props: {
      [EmployeeProps.fired]: true,
    },
    join: 'AND',
  });
  return data;
}, transacted);
```

{% endtab %}

{% tab title="MySQLX" %}

```javascript
// employeeRouter.{ts|js}
import { OffsetPagination, SortBy } from 'crud-node';
import { employeeController } from './employeeController';
import { EmployeeProps } from './schemas/employee';

const transacted = true;

await db.usingSession(async (session) => {
  const sort = SortBy().asc(EmployeeProps.createdAt).toCriteria();
  const data = await employeeController.fetchAll(session, sort, {
    props: {
      [EmployeeProps.fired]: true,
    },
    join: 'AND',
  });
  return data;
}, transacted);
```

{% endtab %}
{% endtabs %}
