mingo
    Preparing search index...

    Class Cursor<T>

    The Cursor class provides a mechanism for iterating over a collection of data with support for filtering, projection, sorting, skipping, and limiting results. It is designed to be chainable and supports lazy evaluation for efficient data processing.

    Type Parameters

    • T

      The type of the elements in the cursor.

    Index

    Constructors

    • Creates an instance of the Cursor class.

      Type Parameters

      • T

      Parameters

      • source: Source

        The source of data to be iterated over.

      • predicate: Predicate<unknown>

        A function or condition to filter the data.

      • projection: AnyObject

        An object specifying the fields to include or exclude in the result.

      • Optionaloptions: Options

        Optional settings to customize the behavior of the cursor.

      Returns Cursor<T>

    Methods

    • Returns an iterator for the cursor, allowing it to be used in for...of loops. The iterator fetches all the results from the cursor.

      Returns Iterator

      An iterator over the fetched results.

    • Return remaining objects in the cursor as an array. This method exhausts the cursor

      Returns T[]

    • Returns the number of objects return in the cursor. This method exhausts the cursor

      Returns number

    • Iterates over all elements in the cursor and executes the provided callback function for each element.

      Parameters

      • fn: Callback<void, T>

        A callback function to execute for each element. The function receives the following arguments:

        • t: The current element being processed in the cursor.
        • i: The index of the current element in the array.
        • a: The array of all elements in the cursor.

      Returns void

    • Determines if there are more elements available in the cursor.

      This method checks if there are any elements left in the internal buffer. If the buffer is empty, it attempts to fetch the next element from the source. If a new element is found, it is added to the buffer and the method returns true. Otherwise, it returns false indicating no more elements are available.

      Returns boolean

      true if there are more elements to iterate over, otherwise false.

    • Limits the number of items returned by the cursor.

      Parameters

      • n: number

        The maximum number of items to return.

      Returns Cursor<T>

      The current cursor instance for chaining.

    • Transforms the elements of the cursor using the provided callback function.

      Type Parameters

      • R

        The type of the elements in the resulting array.

      Parameters

      • fn: Callback<R, T>

        A callback function that is invoked for each element in the cursor. It receives the current element, its index, and the entire array as arguments.

      Returns R[]

      An array of transformed elements of type R.

    • Retrieves the next item in the cursor.

      If there are items in the internal buffer, the next item is returned from the buffer. Otherwise, it fetches the next item from the underlying data source.

      Returns T

      The next item of type T if available, or undefined if there are no more items.

    • Returns a cursor that begins returning results only after passing or skipping a number of documents.

      Parameters

      • n: number

        the number of results to skip.

      Returns Cursor<T>

      Returns the cursor, so you can chain this call.

    • Returns results ordered according to a sort specification.

      Parameters

      • modifier: AnyObject

        an object of key and values specifying the sort order. 1 for ascending and -1 for descending

      Returns Cursor<T>

      Returns the cursor, so you can chain this call.