Setting Query Options in Go OJAI

There are two categories of options you can set in your Go OJAI application. This topic describes both and shows you how to set each.

Setting Query Options Using a Go OJAI Function Call

Option Name Description
IncludeQueryPlan Enables or disables availability of the query plan for retrieval.

Value: true|false

Default: false

ResultAsDocument Enables or disables returning the query result as an OJAI Document object list versus a Go map list.

Value: True|False

Default: False: returns query result as a Go map list

Timeout Query timeout in milliseconds.

Maximum allowed value is 2147483647

Default: None; no timeout

To set any of these query options, you must pass the option as the second parameter in the DocumentStore.FindQueryWithContext function.

The following code snippet sets the query timeout to 3000 milliseconds:

timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Duration(3*time.Second))
result, err := suite.store.FindQueryWithContext(query, findOptions, timeoutCtx)
cancel()

Setting Query Options in Go Using OJAI Query Syntax

OJAI Query Options describes query options that are available in all OJAI clients. To use these options in Go OJAI, you must construct your query in JSON format and use the $options keyword. See OJAI Query Syntax for details about the syntax, including an example.