> For the complete documentation index, see [llms.txt](https://coldbox-orm.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox-orm.ortusbooks.com/v5.x/base-orm-service/dynamic-finders-counters/query-options.md).

# Query Options

If you pass a structure as the last argument to your dynamic finder/counter call, we will consider that by convention to be your query options. A struct is treated as options when it contains at least one of the option keys below.

```javascript
user = getInstance( "User" )
    .findByLastName( "Majano", { ignoreCase : true, timeout : 20 } );

users = getInstance( "User" )
    .findAllByLastNameLike( "Ma%", { maxResults : 20, offset : 15, sortBy : "lastName desc" } );
```

The valid query options are:

* `ignoreCase` : Accepted for backwards compatibility and ignored.
* `maxResults` : Specifies the maximum number of objects to be retrieved.
* `offset` : Specifies the start index of the resultset from where it has to start the retrieval.
* `cacheable` : Whether the result of this query is to be cached in the secondary cache. Default is false.
* `cacheName` : Name of the cache in secondary cache.
* `timeout` : Specifies the timeout value (in seconds) for the query
* `datasource` : The datasource to use, it defaults to the service's datasource
* `sortBy` : The properties to sort by, each with an optional `asc` or `desc`: `"lastName desc, firstName"`. Property names and paths only; anything else raises `InvalidSortOrder`, so it can never inject HQL. Names can be in any case.
* `asStream` : Return a Java `Stream` read from the database as it is consumed. See [Java Streams](/v5.x/advanced/java-streams.md).
* `readOnly`, `uniqueFirst`, `fetchSize` : Passed to `bx-orm`'s `ormExecuteQuery()`.
* `autoCast` : Accepted for backwards compatibility and ignored: `bx-orm` converts values itself.

Here is a more descriptive key set with the types and defaults

```javascript
{
    ignoreCase     : boolean (false)
    maxResults     : numeric (0)
    offset         : numeric (0)
    cacheable      : boolean (false)
    cacheName      : string (default)
    timeout        : numeric (0)
    datasource     : string (defaults)
    sortBy         : properties to sort by ("lastName desc, firstName"),
    asStream       : boolean (false),
    readOnly       : boolean (false),
    uniqueFirst    : boolean (false),
    fetchSize      : numeric
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox-orm.ortusbooks.com/v5.x/base-orm-service/dynamic-finders-counters/query-options.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
