---
title: "Put Custom Sorter Operation"
url: "https://docs.ravendb.net/6.2/client-api/operations/maintenance/sorters/put-sorter"
version: "6.2"
language: "nodejs"
---

# Put Custom Sorter Operation

> Client language: Node.js. Also available for [C#](https://docs.ravendb.net/6.2/client-api/operations/maintenance/sorters/put-sorter.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."

> **Note**
>
> - The Lucene indexing engine allows you to create your own **Custom Sorters**  
>   where you can define how query results will be ordered based on your specific requirements.
>
> - Use `PutSortersOperation` to deploy a custom sorter to the RavenDB server.  
>   Once deployed, you can use it to sort query results for all queries made on the **database**  
>   that is scoped to your [Document Store](https://docs.ravendb.net/6.2/client-api/setting-up-default-database.nodejs.md).
>
> - To deploy a custom sorter that will apply cluster-wide, to all databases, see [put server-wide sorter](https://docs.ravendb.net/6.2/client-api/operations/server-wide/sorters/put-sorter-server-wide.nodejs.md).
>
> - A custom sorter can also be uploaded to the server from the [Studio](https://docs.ravendb.net/6.2/studio/database/settings/custom-sorters.md).
>
> - In this page:
>   - [Put custom sorter](#put-custom-sorter)
>   - [Syntax](#syntax)

## Put custom sorter

- First, create your own sorter class that inherits from the Lucene class [Lucene.Net.Search.FieldComparator](https://lucenenet.apache.org/docs/3.0.3/df/d91/class_lucene_1_1_net_1_1_search_1_1_field_comparator.html).

- Then, send the custom sorter to the server using the `PutSortersOperation`.

```javascript
// Create the sorter definition object
const sorterDefinition = {
  // The sorter name must be the same as the sorter's class name in your code
  name: "MySorter",
  // The code must be compilable and include all necessary using statements (C# code)
  code: "<code of custom sorter>"
};

// Define the put sorters operation, pass the sorter definition
const putSorterOp = new PutSortersOperation(sorterDefinition);

// Execute the operation by passing it to maintenance.send
await documentStore.maintenance.send(putSorterOp);
```

> **Note**
>
> You can now order your query results using the custom sorter.  
> A query example is available [here](https://docs.ravendb.net/6.2/client-api/session/querying/sort-query-results.nodejs.md#custom-sorters).

## Syntax

```javascript
const putSorterOp = new PutSortersOperation(sortersToAdd);
```

| Parameter | Type | Description |
| - | - | - |
| **sortersToAdd** | `...object[]` | One or more Sorter Definition objects to send to the server |

```javascript
// The sorter definition object 
{
  name: string;
  code: string;
}
```

## See also

- [Sort query results](https://docs.ravendb.net/6.2/client-api/session/querying/sort-query-results.nodejs.md)
- [What are operations](https://docs.ravendb.net/6.2/client-api/operations/what-are-operations.nodejs.md)
- [Put server-wide sorter](https://docs.ravendb.net/6.2/client-api/operations/server-wide/sorters/put-sorter-server-wide.nodejs.md)
- [Custom sorters view](https://docs.ravendb.net/6.2/studio/database/settings/custom-sorters.md)
