Skip to content

query

Reads or rewrites params.query.

NameCategoryDescription
cache
hooks

Caches get and find results based on params. On mutating methods (create, update, patch, remove), affected cache entries are automatically invalidated. Works as a before, after, or around hook.

disablePagination
hooks

Disables pagination when query.$limit is -1 or '-1'. Removes the $limit from the query and sets params.paginate = false. Must be used as a before or around hook on the find method.

findOrCreate
hooks

A before:create (or around:create) hook that looks for an existing record before creating one.

It builds a query from the uniqueBy paths read out of context.data, runs find({ paginate: false }) on the target service, and if exactly one record matches, sets context.result to that record — short-circuiting the create. With zero matches (or array data) the create proceeds; with multiple matches the onMultiple option decides.

setField
hooks

Sets a field on the hook context (e.g. params.query) based on the value of another context field (e.g. params.user.id). Useful for scoping queries to the authenticated user. Throws a Forbidden error if the source field is missing (unless allowUndefined is true).

setQueryDefaults
hooks

Adds default properties to context.params.query for fields the incoming query does not already constrain (including fields referenced nested in $and/$or/$nor). The query equivalent of the defaults transformer: e.g. hide template rows by default while still letting callers opt in via { isTemplate: true }. This is the same pattern softDelete uses to filter out deleted rows. Works as a before or around hook.

setSlug
hooks

Extracts URL route parameters (slugs) and sets them on params.query. For example, given a route /stores/:storeId, this hook copies the resolved storeId value from params.route into the query. Only applies to the rest provider.

softDelete
hooks

Marks items as deleted instead of physically removing them. On remove, the hook patches the record with removeData (e.g. { deletedAt: new Date() }). On all other methods, it appends deletedQuery (e.g. { deletedAt: null }) to filter out soft-deleted items.

transformQuery
hooks

Transforms context.params.query using the provided transformer function. The transformer receives the current query and can return a modified version. Useful for normalizing, sanitizing, or enriching queries before they hit the database.

traverse
hooks

Recursively walks and transforms fields in record(s) using neotraverse. The getObject function extracts the target from the context, and transformer is called for every node during traversal --- ideal for deep, structural transformations.

addToQuery
utils

Safely merges properties into a Feathers query object. If a property already exists with a different value, it wraps both in a $and array to preserve both conditions. If the exact same key-value pair already exists, no changes are made. When the added query is itself a pure $and ({ $and: [...] }), its branches are flattened into the target's $and rather than nested.

The added query narrows the target — every condition is kept, so the result matches at most what the target matched. Two conditions on the same property are therefore intersected, never unioned: adding { role: 'b' } to { role: 'a' } matches nothing, it does not become { role: { $in: ['a', 'b'] } }. Use {@link mergeQuery} with its default combine mode when you want to broaden a query instead.

The query filters $select, $limit, $skip and $sort are split off and merged separately, never wrapped in an $and where no adapter would evaluate them. Since addToQuery narrows, they follow the same rules as {@link mergeQuery} in intersect mode: the added query wins for $limit and $skip, $sort is merged key by key (the added query wins per key, the target keeps the leading sort order), and $select becomes the intersection of both. A filter only one side provides is kept as it is.

chunkFind
utils

Use for await to iterate over chunks (pages) of results from a find method.

This function is useful for processing large datasets in batches without loading everything into memory at once. It uses pagination to fetch results in chunks, yielding each page's data array.

dotifyQuery
utils

Converts the nested properties of a Feathers query into dot notation — { user: { name: 'x' } } becomes { 'user.name': 'x' }. This is the form every Feathers adapter understands, so it is the direction you normally want.

The conversion is query-aware rather than a generic object flatten:

  • operators ($ne, $in, ...) never become path segments
  • $or/$and/$nor/$not branches are converted individually
  • $sort keys are flattened, its directions are kept
  • $select, $limit, $skip and custom operators pass through untouched

A value is only treated as a path when it is a non-empty plain object with at least one non-$ key. Date, RegExp, bson ObjectId, class instances, arrays, primitives and {} are always values. An object that mixes operators and plain keys keeps its operators on the current path: { user: { $ne: null, name: 'x' } } becomes { user: { $ne: null }, 'user.name': 'x' }.

Use descend, exclude or include for properties that legitimately hold an object value. The query is not mutated and is returned unchanged (same reference) when there was nothing to convert.

Nothing is ever dropped when two paths collide. Deep-equal values collapse into one, operator objects with disjoint keys merge, and a genuine contradiction is wrapped in $and — the colliding keys were an implicit AND to begin with. This matches {@link addToQuery}.

eqOrIn
utils

Turns a list of values into a query value that matches any of them: a single remaining value becomes an equality match, everything else a $in. Values are deduplicated first, so ['a', 'a'] collapses to the equality form. An empty list yields { $in: [] }, matching nothing — check for emptiness first if your adapter dislikes an empty IN ().

Deduplication compares primitives with SameValueZero and non-primitives deep-equal, so value wrappers like Date or a mongo ObjectId collapse even though they are distinct references. Note that deep equality ignores key order, so two plain objects with the same entries in a different order count as one.

iterateFind
utils

Use for await to iterate over the results of a find method.

This function is useful for iterating over large datasets without loading everything into memory at once. It uses pagination to fetch results in chunks, allowing you to process each item as it is retrieved.

mergeQuery
utils

Properties are combined with a logical operator rather than merged at the value level, so the result is always a valid query: combine always wraps the two queries in $or (broaden — OR has no flat form), while intersect merges non-conflicting properties flat and wraps conflicts in $and (narrow). The special filters $select, $limit, $skip and $sort are merged separately. Inputs are never mutated.

Under combine, branches that constrain the same single property with an equality or an $in are collapsed into a single $in over the union of their values — the same condition, without the $or (opt out with collapseOrToIn: false).

This is well suited to merging a client-provided query with a server-side restriction inside a hook.

neOrNin
utils

Turns a list of values into a query value that excludes all of them: a single remaining value becomes { $ne: value }, everything else { $nin: values }. Values are deduplicated first, so ['a', 'a'] collapses to the $ne form. An empty list yields { $nin: [] }, excluding nothing — check for emptiness first if your adapter dislikes an empty NOT IN ().

Deduplication compares primitives with SameValueZero and non-primitives deep-equal, so value wrappers like Date or a mongo ObjectId collapse even though they are distinct references. Note that deep equality ignores key order, so two plain objects with the same entries in a different order count as one.

nestifyQuery
utils

Converts the dot-notation properties of a Feathers query into nested objects — { 'user.name': 'x' } becomes { user: { name: 'x' } }. This is the inverse of {@link dotifyQuery}.

The conversion is query-aware rather than a generic object unflatten:

  • $or/$and/$nor/$not branches are converted individually
  • $sort keys are kept in dot notation (nested ones are flattened), because that is the only form the Feathers adapters understand
  • $select, $limit, $skip and custom operators pass through untouched — $select holds paths as values, not as keys
  • a path containing a $-prefixed segment is never split

Use split, exclude or include for keys whose dots are meaningful data. The query is not mutated and is returned unchanged (same reference) when there was nothing to convert.

Nothing is ever dropped when two keys collide. Deep-equal values collapse into one, objects with disjoint keys merge, and a genuine contradiction is wrapped in $and, since the colliding keys were an implicit AND to begin with — this matches {@link addToQuery}. A key whose path is blocked by a non-object value needs no $and at all: it simply stays in dot notation, which is already a valid condition.

Caveat: this direction is best effort and not semantics-preserving on MongoDB, where { user: { name: 'x' } } means document equality while { 'user.name': 'x' } means a subfield match. dotifyQuery is the reliable direction; reach for nestifyQuery when a consumer genuinely needs the nested shape.

queryDefaults
utils

Adds default properties to a Feathers query — but only for fields the query does not already constrain. Presence is checked with {@link queryHasProperty}, so a field referenced anywhere (including nested in $and/$or/$nor) is left untouched and the caller keeps control over it. The query is treated as the data equivalent of the defaults transformer. Each default is applied independently (per-field).

queryHasProperty
utils

Checks whether a Feathers query contains one or more properties — including properties nested inside $and/$or/$nor arrays. Returns true as soon as any of the given property names is found. The query is not mutated.

simplifyQuery
utils

Normalizes the logical structure of a Feathers query without changing what it matches: empty $and/$or are dropped, duplicate branches removed, nested same-operator branches hoisted ($and-in-$and, pure $or-in-$or), $or branches on the same property collapsed into a single $in, single-value $in/$nin written as an equality/$ne, and branches merged up into the parent where it is safe — all of an $and when no key collides, a single-branch $or. Runs recursively. Inputs are not mutated; a query with nothing to simplify is returned unchanged.

sortQueryProperties
utils

Recursively normalizes a Feathers query object for order-independent comparison. Sorts object keys and sorts arrays within $or, $and, $nor, $not, $in, and $nin operators so that different orderings produce the same result.

This is useful for generating stable cache keys where { $or: [{ a: 1 }, { b: 2 }] } and { $or: [{ b: 2 }, { a: 1 }] } should be treated as equivalent.

walkQuery
utils

Walks every property of a Feathers query (including nested $and/$or/$nor arrays) and calls the walker function for each one. The walker receives the property name, operator, value, path, and a stop function, and can return a replacement value. Calling stop() halts the traversal early. Returns a new query only if changes were made.

resolveQuery
resolvers

Resolves and transforms context.params.query using a map of resolver functions. Each property in the resolver object receives the current query value and can return a transformed value. Runs before next() in the hook pipeline.

hasQuery
guards

Type guard to check if the query property of Params is present and non-nullable.

See all tags for the full vocabulary.

Released under the MIT License.