# Example: Sorting

Use the following query option to apply sorting:

### **sorting**

**Type:** `Comfortable.Sorting` \
sort query results ascending or descending by certain fields

#### Parameters

| Name             | Default  | Type   | Description                                                            |
| ---------------- | -------- | ------ | ---------------------------------------------------------------------- |
| **field API ID** |          | String | The field API ID sorting is applied to                                 |
| **direction**    | `desc`   | String | Sorting direction                                                      |
| **context**      | `fields` | String | Context can be either `meta` (meta fields) or `fields`(content fields) |

```javascript
const api = Comfortable.api('<repository-api-id>', '<api-key>');

var options = {
    sorting: new Comfortable.Sorting()
        .add('createdAt', 'asc', 'meta')
        .add('title', 'asc')
}


api.getDocuments(options)
  .then(result => {
    // futher implementation
  })
  .catch(err => {
    throw err;
  })
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.comfortable.io/sdk/javascript/example-sorting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
