mingo

  • Version 6.6.1
  • Published
  • 1.01 MB
  • No dependencies
  • MIT license

Install

npm i mingo
yarn add mingo
pnpm add mingo

Overview

MongoDB query language for in-memory objects

Index

Variables

variable _default

const _default: {
Aggregator: typeof Aggregator;
ProcessingMode: typeof ProcessingMode;
Query: typeof Query;
aggregate: typeof aggregate;
createUpdater: typeof createUpdater;
find: typeof find;
update: import('./updater').Updater;
};

    variable update

    const update: Updater;
    • Updates the given object with the expression.

      Parameter obj

      The object to update.

      Parameter expr

      The update expressions.

      Parameter arrayFilters

      Filters to apply to nested items.

      Parameter conditions

      Conditions to validate before performing update.

      Parameter options

      Update options to override defaults.

      Returns

      {string[]} A list of modified field paths in the object.

    Functions

    function aggregate

    aggregate: (
    collection: Source,
    pipeline: AnyObject[],
    options?: Partial<Options>
    ) => AnyObject[];
    • Performs an aggregation operation on the provided collection using the specified pipeline.

      Parameter collection

      The input data source to aggregate.

      Parameter pipeline

      An array of aggregation stages to process the collection.

      Parameter options

      Optional settings to customize the aggregation behavior.

      Returns

      The result of the aggregation as an array of objects.

    function createUpdater

    createUpdater: (defaultOptions?: UpdateOptions) => Updater;
    • Creates a new updater function with default options.

      Parameter defaultOptions

      The default options. Defaults to no cloning with strict mode off for queries.

      Returns

      {Updater}

    function find

    find: <T>(
    collection: Source,
    criteria: AnyObject,
    projection?: AnyObject,
    options?: Partial<Options>
    ) => Cursor<T>;
    • Finds documents in a collection that match the specified criteria.

      T - The type of the documents in the collection.

      Parameter collection

      The source collection to search.

      Parameter criteria

      The query criteria to filter the documents.

      Parameter projection

      Optional. Specifies the fields to include or exclude in the returned documents.

      Parameter options

      Optional. Additional options to customize the query behavior.

      Returns

      A Cursor object that allows iteration over the matching documents.

    Classes

    class Aggregator

    class Aggregator {}
    • The Aggregator class provides functionality to process data collections through an aggregation pipeline. It supports streaming and executing aggregation operations with customizable options.

    constructor

    constructor(pipeline: AnyObject[], options?: Partial<Options>);
    • Creates an instance of the Aggregator class.

      Parameter pipeline

      An array of objects representing the aggregation pipeline stages.

      Parameter options

      Optional configuration settings for the aggregator.

    method run

    run: <T extends AnyObject>(collection: Source, options?: Options) => T[];
    • Executes the aggregation pipeline on the provided collection and returns the resulting array.

      T - The type of the objects in the resulting array.

      Parameter collection

      The input data source to run the aggregation on.

      Parameter options

      Optional settings to customize the aggregation behavior.

      Returns

      An array of objects of type T resulting from the aggregation.

    method stream

    stream: (collection: Source, options?: Options) => Iterator;
    • Processes a collection through an aggregation pipeline and returns an iterator for the transformed results.

      Parameter collection

      The input collection to process. This can be any source that implements the Source interface.

      Parameter options

      Optional configuration for processing. If not provided, the default options of the aggregator instance will be used.

      Returns

      An iterator that yields the results of the aggregation pipeline.

      Throws

      Will throw an error if: - A pipeline stage contains more than one operator. - The $documents operator is not the first stage in the pipeline. - An unregistered pipeline operator is encountered.

    class Query

    class Query {}
    • Represents a query object used to filter and match documents based on specified criteria.

      The Query class provides methods to compile query conditions, test objects against the query criteria, and retrieve matching documents from a collection.

      Example 1

      const query = new Query({ age: { $gt: 18 } });
      const result = query.test({ name: "John", age: 25 }); // true

      T - The type of objects being queried.

    constructor

    constructor(condition: AnyObject, options?: Partial<Options>);
    • Creates an instance of the query with the specified condition and options.

      Parameter condition

      The query condition object used to define the criteria for matching documents.

      Parameter options

      Optional configuration settings to customize the query behavior.

    method find

    find: <T>(collection: Source, projection?: AnyObject) => Cursor<T>;
    • Returns a cursor for iterating over the items in the given collection that match the query criteria.

      Parameter collection

      The source collection to search through.

      Parameter projection

      An optional object specifying fields to include or exclude in the returned items.

      Returns

      A Cursor instance for iterating over the matching items.

    method test

    test: <T>(obj: T) => boolean;
    • Tests whether the given object satisfies all compiled predicates.

      T - The type of the object to test.

      Parameter obj

      The object to be tested against the compiled predicates.

      Returns

      true if the object satisfies all predicates, otherwise false.

    Enums

    enum ProcessingMode

    enum ProcessingMode {
    CLONE_OFF = 0,
    CLONE_INPUT = 1,
    CLONE_OUTPUT = 2,
    CLONE_ALL = 3,
    }
    • Enum representing the processing modes for handling input and output documents. This determines whether cloning is applied to maintain immutability or ensure distinct object references.

    member CLONE_ALL

    CLONE_ALL = 3
    • Clone both input and output documents. Combines CLONE_INPUT and CLONE_OUTPUT.

    member CLONE_INPUT

    CLONE_INPUT = 1
    • Clone input documents to maintain immutability of the original input.

    member CLONE_OFF

    CLONE_OFF = 0
    • Do not clone inputs or outputs. Resulting documents may share references. This is the default mode.

    member CLONE_OUTPUT

    CLONE_OUTPUT = 2
    • Clone output documents to ensure distinct objects without shared references.

    Package Files (5)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (0)

    No dev dependencies.

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/mingo.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/mingo)
    • HTML
      <a href="https://www.jsdocs.io/package/mingo"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>