Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ArrayCursor<T>

TODO

Type parameters

  • T

Hierarchy

  • ArrayCursor

Index

Accessors

count

  • get count(): number | undefined
  • The total number of documents in the query result. Only available if the count option was used.

    Returns number | undefined

extra

  • get extra(): { plan?: any; profile?: any; stats?: Dict<any>; warnings: { code: number; message: string }[] }
  • TODO

    Returns { plan?: any; profile?: any; stats?: Dict<any>; warnings: { code: number; message: string }[] }

    • Optional plan?: any
    • Optional profile?: any
    • Optional stats?: Dict<any>
    • warnings: { code: number; message: string }[]

hasMore

  • get hasMore(): boolean
  • Whether the cursor has any remaining batches that haven't yet been fetched. If set to false, all batches have been fetched and no additional requests to the server will be made when consuming any remaining items from this cursor.

    Returns boolean

hasNext

  • get hasNext(): boolean
  • Whether the cursor has more values. If set to false, the cursor has already been depleted and contains no more items.

    Returns boolean

Methods

[Symbol.asyncIterator]

  • [Symbol.asyncIterator](): AsyncGenerator<T, undefined, undefined>
  • Enables use with for await to deplete the cursor by asynchronously yielding every value in the cursor's remaining result set.

    Note: If the result set spans multiple batches, any remaining batches will only be fetched on demand. Depending on the cursor's TTL and the processing speed, this may result in the server discarding the cursor before it is fully depleted.

    example
    const cursor = await db.query(aql`
      FOR user IN users
      FILTER user.isActive
      RETURN user
    `);
    for await (const user of cursor) {
      console.log(user.email, user.isAdmin);
    }

    Returns AsyncGenerator<T, undefined, undefined>

all

  • all(): Promise<T[]>
  • Depletes the cursor, then returns an array containing all values in the cursor's remaining result list.

    example
    const cursor = await db.query(aql`FOR x IN 1..5 RETURN x`);
    const result = await cursor.all(); // [1, 2, 3, 4, 5]
    console.log(cursor.hasNext); // false

    Returns Promise<T[]>

flatMap

  • flatMap<U>(fn: (value: T, index: number, self: ArrayCursor<T>) => U): Promise<U[]>
  • TODO

    Type parameters

    • U

    Parameters

    • fn: (value: T, index: number, self: ArrayCursor<T>) => U
        • Parameters

          Returns U

    Returns Promise<U[]>

forEach

  • forEach(fn: (value: T, index: number, self: ArrayCursor<T>) => boolean | void): Promise<boolean>
  • TODO

    Parameters

    • fn: (value: T, index: number, self: ArrayCursor<T>) => boolean | void
        • (value: T, index: number, self: ArrayCursor<T>): boolean | void
        • Parameters

          Returns boolean | void

    Returns Promise<boolean>

kill

  • kill(): Promise<void>
  • TODO

    Returns Promise<void>

map

  • map<U>(fn: (value: T, index: number, self: ArrayCursor<T>) => U): Promise<U[]>
  • TODO

    Type parameters

    • U

    Parameters

    • fn: (value: T, index: number, self: ArrayCursor<T>) => U
        • Parameters

          Returns U

    Returns Promise<U[]>

next

  • next(): Promise<T | undefined>
  • Advances the cursor and returns the next value in the cursor's remaining result list, or undefined if the cursor has been depleted.

    Note: If the result set spans multiple batches, any remaining batches will only be fetched on demand. Depending on the cursor's TTL and the processing speed, this may result in the server discarding the cursor before it is fully depleted.

    example
    const cursor = await db.query(aql`FOR x IN 1..3 RETURN x`);
    const one = await cursor.next(); // 1
    const two = await cursor.next(); // 2
    const three = await cursor.next(); // 3
    const empty = await cursor.next(); // undefined

    Returns Promise<T | undefined>

nextBatch

  • nextBatch(): Promise<any[] | undefined>
  • Advances the cursor and returns all remaining values in the cursor's current batch. If the current batch has already been exhausted, fetches the next batch from the server and returns it, or undefined if the cursor has been depleted.

    Note: If the result set spans multiple batches, any remaining batches will only be fetched on demand. Depending on the cursor's TTL and the processing speed, this may result in the server discarding the cursor before it is fully depleted.

    example
    const cursor = await db.query(
      aql`FOR i IN 1..10 RETURN i`,
      { batchSize: 5 }
    );
    const firstBatch = await cursor.nextBatch(); // [1, 2, 3, 4, 5]
    await cursor.next(); // 6
    const lastBatch = await cursor.nextBatch(); // [7, 8, 9, 10]
    console.log(cursor.hasNext); // false

    Returns Promise<any[] | undefined>

reduce

  • reduce<U>(fn: (accu: U, value: T, index: number, self: ArrayCursor<T>) => U, accu?: U): Promise<U | undefined>
  • TODO

    Type parameters

    • U

    Parameters

    • fn: (accu: U, value: T, index: number, self: ArrayCursor<T>) => U
        • (accu: U, value: T, index: number, self: ArrayCursor<T>): U
        • Parameters

          Returns U

    • Optional accu: U

    Returns Promise<U | undefined>

Generated using TypeDoc