Skip to content

removeMany ​

Category
Tags
Export size
min 7.62 kB · gzip 3.09 kB
See also

Removes all items matching params with a single remove(null, ...) call.

If the service does not allow multi removing (its multi option, or an explicit multi option), the matching items are fetched with find and removed with one call per item instead, at most concurrency at a time - so it works regardless of the service's multi configuration.

The params only select which items are affected: the query is consumed by the find - which only collects the ids - and is not applied again for the per-item calls, except $select.

ts
  import { 
removeMany
} from 'feathers-utils/utils';

Example ​

ts
import { removeMany } from 'feathers-utils/utils'

// one `remove(null, ...)` call, or one `remove(id, ...)` call per item
const todos = await removeMany(app, 'todos', { query: { userId: 1 } })

Options ​

multiMulti

Whether the service allows removing multiple items in a single call.

Defaults to the multi option of the service. If multi removing is not allowed, the matching items are fetched and removed with one call per item.

concurrencynumberdefault10

How many remove calls run at the same time when the items are removed with one call per item, so a large match does not exhaust the database pool.

Type declaration ​

Show Type Declarations
ts
export type RemoveManyOptions = {
  /**
   * Whether the service allows removing multiple items in a single call.
   *
   * Defaults to the `multi` option of the service. If multi removing is not
   * allowed, the matching items are fetched and removed with one call per item.
   */
  multi?: Multi
  /**
   * How many `remove` calls run at the same time when the items are removed with
   * one call per item, so a large match does not exhaust the database pool.
   *
   * @default 10
   */
  concurrency?: number
}
/**
 * Removes all items matching `params` with a single `remove(null, ...)` call.
 *
 * If the service does not allow multi removing (its `multi` option, or an
 * explicit `multi` option), the matching items are fetched with `find` and
 * removed with one call per item instead, at most `concurrency` at a time - so
 * it works regardless of the service's `multi` configuration.
 *
 * The `params` only select which items are affected: the query is consumed by
 * the `find` - which only collects the ids - and is not applied again for the
 * per-item calls, except `$select`.
 *
 * @example
 * ```ts
 *
 *
 * // one `remove(null, ...)` call, or one `remove(id, ...)` call per item
 * const todos = await removeMany(app, 'todos', { query: { userId: 1 } })
 * ```
 *
 * @see https://utils.feathersjs.com/utils/remove-many.html
 */
export declare function removeMany<
  Services,
  Path extends KeyOf<Services>,
  Service extends Services[Path] = Services[Path],
  P extends Params = InferFindParams<Service>,
  Item = InferFindResultSingle<Service>,
>(
  app: Application<Services>,
  servicePath: Path,
  params?: P,
  options?: RemoveManyOptions,
): Promise<Item[]>
ArgumentTypeDescription
appApplication<Services>
servicePathPath
paramsP
optionsRemoveManyOptions

Released under the MIT License.