Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Cursor<TDocument, TInstance>

An Iridium collection cursor which allows the itteration through documents in the collection, automatically wrapping them in the correct instance type.

Type parameters

  • TDocument: object

    The interface representing the collection's documents

  • TInstance

    The interface or class used to represent the wrapped documents.

Hierarchy

  • Cursor

Index

Constructors

constructor

  • new Cursor(model: Model<TDocument, TInstance>, conditions: any, cursor: Cursor<TDocument>): Cursor
  • Creates a new Iridium cursor which wraps a MongoDB cursor object

    constructor

    Parameters

    • model: Model<TDocument, TInstance>

      The Iridium model that this cursor belongs to

    • conditions: any

      The conditions that resulte in this cursor being created

    • cursor: Cursor<TDocument>

      The MongoDB native cursor object to be wrapped

    Returns Cursor

Properties

Private conditions

conditions: any

The conditions that resulte in this cursor being created

cursor

cursor: Cursor<TDocument>

The MongoDB native cursor object to be wrapped

Private model

model: Model<TDocument, TInstance>

The Iridium model that this cursor belongs to

Methods

count

  • count(callback?: General.Callback<number>): Promise<number>
  • Counts the number of documents which are matched by this cursor

    Parameters

    • Optional callback: General.Callback<number>

    Returns Promise<number>

    A promise which will resolve with the number of documents matched by this cursor

forEach

  • forEach(handler: function, callback?: General.Callback<void>): Promise<void>
  • Runs the specified handler over each instance in the query results

    Parameters

    • handler: function

      The handler which is triggered for each element in the query

        • (instance: TInstance): void
        • Parameters

          • instance: TInstance

          Returns void

    • Optional callback: General.Callback<void>

    Returns Promise<void>

    A promise which is resolved when all operations have been dispatched

limit

  • limit(limit: number): Cursor<TDocument, TInstance>
  • Returns a new cursor which limits the number of returned results

    Parameters

    • limit: number

      The maximum number of results to return

    Returns Cursor<TDocument, TInstance>

    The new cursor which will return a maximum number of results

map

  • map<TResult>(transform: function, callback?: General.Callback<TResult[]>): Promise<TResult[]>
  • Runs the specified transform over each instance in the query results and returns the resulting transformed objects

    Type parameters

    • TResult

    Parameters

    • transform: function

      A handler which is used to transform the result objects

        • (instance: TInstance): TResult | Promise<TResult>
        • Parameters

          • instance: TInstance

          Returns TResult | Promise<TResult>

    • Optional callback: General.Callback<TResult[]>

    Returns Promise<TResult[]>

    A promise which is fulfilled with the results of the transformations

next

  • next(callback?: General.Callback<TInstance>): Promise<TInstance | undefined>
  • Retrieves the next item in the results list

    Parameters

    • Optional callback: General.Callback<TInstance>

    Returns Promise<TInstance | undefined>

    A promise which is resolved with the next item

one

  • one(callback?: General.Callback<TInstance>): Promise<TInstance | undefined>
  • Retrieves the next item in the result list and then closes the cursor

    Parameters

    • Optional callback: General.Callback<TInstance>

    Returns Promise<TInstance | undefined>

    A promise which is resolved once the item becomes available and the cursor has been closed.

readFrom

  • readFrom(type: string): Cursor<TDocument, TInstance>

rewind

  • rewind(): Cursor<TDocument, TInstance>
  • Returns a new cursor which behaves the same as this one did before any results were retrieved

    Returns Cursor<TDocument, TInstance>

    The new cursor which starts at the beginning of the results

skip

  • skip(skip: number): Cursor<TDocument, TInstance>
  • Returns a new cursor which skips a number of results before it begins returning any.

    Parameters

    • skip: number

      The number of results to skip before the cursor beings returning

    Returns Cursor<TDocument, TInstance>

    The new cursor which skips a number of results

sort

  • Returns a new cursor which sorts its results by the given index expression

    Parameters

    • sortExpression: IndexSpecification

      The index expression dictating the sort order and direction to use

    Returns Cursor<TDocument, TInstance>

    The new cursor which sorts its results by the sortExpression

toArray

  • toArray(callback?: General.Callback<TInstance[]>): Promise<TInstance[]>
  • Retrieves all matching instances and returns them in an array

    Parameters

    • Optional callback: General.Callback<TInstance[]>

    Returns Promise<TInstance[]>

    A promise which resolves with the instances returned by the query

Generated using TypeDoc