Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AggregationCursor<TSchema>

The AggregationCursor class is an internal class that embodies an aggregation cursor on MongoDB allowing for iteration over the results returned from the underlying query. AggregationCursor类是一个内部类,它在MongoDB上体现了一个聚合游标,允许对从底层查询返回的结果进行迭代。It supports one by one document iteration, conversion to an array or can be iterated as a Node 4.X or higher stream它支持一个接一个的文档迭代、到数组的转换,或者可以作为Node 4.x或更高的流进行迭代

(?<=)Type parameters类型参数

Hierarchy层级

Index索引

Constructors构造函数

constructor

Events事件

Static Readonly CLOSE

CLOSE: "close" = ...

Properties属性

[kClosed]

[kClosed]: boolean
internal

[kDocuments]

[kDocuments]: TSchema[]
internal

Optional [kId]

[kId]: Long
internal

[kInitialized]

[kInitialized]: boolean
internal

[kKilled]

[kKilled]: boolean
internal

[kNamespace]

[kNamespace]: MongoDBNamespace
internal

[kOptions]

[kOptions]: AggregateOptions
internal

[kOptions]

internal

[kPipeline]

[kPipeline]: Document[]
internal

Optional [kServer]

[kServer]: Server
internal

Optional [kSession]

[kSession]: ClientSession
internal

[kTopology]

[kTopology]: Topology
internal

Optional [kTransform]

[kTransform]: (doc: TSchema) => Document
internal

Type declaration类型声明

    • internal

      Parameters参数

      • doc: TSchema

      Returns返回Document

Static Readonly captureRejectionSymbol

captureRejectionSymbol: typeof captureRejectionSymbol

Static captureRejections

captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.设置或获取所有发射器的默认captureRejection值。

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events.此符号应用于安装仅用于监控'error'事件的侦听器。Listeners installed using this symbol are called before the regular 'error' listeners are called.在调用常规'error'侦听器之前,将调用使用此符号安装的侦听器。

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.使用此符号安装侦听器不会在发出'error'事件后更改行为,因此如果未安装常规的'error'侦听器,进程仍将崩溃。

Accessors访问器

closed

  • get closed(): boolean

cursorOptions

id

  • get id(): undefined | Long

killed

  • get killed(): boolean

loadBalanced

  • get loadBalanced(): boolean

namespace

pipeline

readConcern

readPreference

server

  • get server(): undefined | Server

session

topology

Methods方法

[asyncIterator]

  • [asyncIterator](): AsyncIterator<TSchema, void, undefined>

_getMore

_initialize

addCursorFlag

  • addCursorFlag(flag: "tailable" | "awaitData" | "noCursorTimeout" | "oplogReplay" | "exhaust" | "partial", value: boolean): AggregationCursor<TSchema>
  • Add a cursor flag to the cursor向游标添加游标标志

    Parameters参数

    • flag: "tailable" | "awaitData" | "noCursorTimeout" | "oplogReplay" | "exhaust" | "partial"

      The flag to set, must be one of following ['tailable', 'oplogReplay', 'noCursorTimeout', 'awaitData', 'partial' -.要设置的标志必须是以下['tailable', 'oplogReplay', 'noCursorTimeout', 'awaitData', 'partial']-之一。

    • value: boolean

      The flag boolean value.标志布尔值。

    Returns返回AggregationCursor<TSchema>

addListener

batchSize

bufferedCount

  • bufferedCount(): number

clone

close

emit

  • emit<EventKey>(event: symbol | EventKey, ...args: Parameters<AbstractCursorEvents[EventKey]>): boolean

eventNames

  • eventNames(): string[]

explain

forEach

  • forEach(iterator: (doc: TSchema) => boolean | void): Promise<void>
  • forEach(iterator: (doc: TSchema) => boolean | void, callback: Callback<void>): void
  • Iterates over all the documents for this cursor using the iterator, callback pattern.使用迭代器回调模式遍历该游标的所有文档。

    Parameters参数

    • iterator: (doc: TSchema) => boolean | void

      The iteration callback.

        • (doc: TSchema): boolean | void
        • Parameters参数

          • doc: TSchema

          Returns返回boolean | void

    Returns返回Promise<void>

  • Parameters参数

    • iterator: (doc: TSchema) => boolean | void
        • (doc: TSchema): boolean | void
        • Parameters参数

          • doc: TSchema

          Returns返回boolean | void

    • callback: Callback<void>

    Returns返回void

geoNear

getMaxListeners

  • getMaxListeners(): number

group

hasNext

  • hasNext(): Promise<boolean>
  • hasNext(callback: Callback<boolean>): void

limit

listenerCount

  • listenerCount<EventKey>(type: string | symbol | EventKey): number

listeners

lookup

map

  • Map all documents using the provided function If there is a transform set on the cursor, that will be called first and the result passed to this function's transform.如果游标上有一个转换集,则使用提供的函数映射所有文档,该转换集将首先被调用,并将结果传递给该函数的转换。

    remarks

    Note for Typescript Users:Typescript用户注意: adding a transform changes the return type of the iteration of this cursor, it does not return a new instance of a cursor. 添加转换会更改此游标迭代的返回类型,但不会返回游标的新实例。This means when calling map, you should always assign the result to a new variable in order to get a correctly typed cursor variable. 这意味着在调用map时,应该始终将结果分配给一个新变量,以便获得正确类型的游标变量。Take note of the following example:请注意以下示例:

    Type parameters类型参数

    • T

    Parameters参数

    • transform: (doc: TSchema) => T
        • (doc: TSchema): T
        • Parameters参数

          • doc: TSchema

          Returns返回T

    Returns返回AggregationCursor<T>

match

maxTimeMS

  • Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher)在游标查询上设置maxTimeMS,允许对查询进行硬超时限制(仅在MongoDB 2.6或更高版本上支持)

    Parameters参数

    • value: number

      Number of milliseconds to wait before aborting the query.中止查询前等待的毫秒数。

    Returns返回AggregationCursor<TSchema>

next

  • next(): Promise<null | TSchema>
  • next(callback: Callback<null | TSchema>): void
  • next(callback?: Callback<null | TSchema>): void | Promise<null | TSchema>

off

on

once

out

prependListener

prependOnceListener

project

  • Add a project stage to the aggregation pipeline将项目阶段添加到聚合管道

    remarks

    In order to strictly type this function you must provide an interface that represents the effect of your projection on the result documents.为了严格地键入此函数,您必须提供一个界面来表示您的投影对结果文档的影响。

    By default chaining a projection to your cursor changes the returned type to the generic Document type. 默认情况下,将投影链接到游标会将返回的类型更改为通用文档类型。You should specify a parameterized type to have assertions on your final results.您应该指定一个参数化类型,以便对最终结果进行断言。

    example
    // Best way
    const docs: AggregationCursor<{ a: number }> = cursor.project<{ a: number }>({ _id: 0, a: true });
    // Flexible way
    const docs: AggregationCursor<Document> = cursor.project({ _id: 0, a: true });
    
    remarks

    In order to strictly type this function you must provide an interface that represents the effect of your projection on the result documents.为了严格地键入此函数,您必须提供一个界面来表示您的投影对结果文档的影响。

    Note for Typescript Users:Typescript用户注意: adding a transform changes the return type of the iteration of this cursor, it does not return a new instance of a cursor. 添加转换会更改此游标迭代的返回类型,但不会返回游标的新实例。This means when calling project, you should always assign the result to a new variable in order to get a correctly typed cursor variable. 这意味着在调用project时,应该始终将结果分配给一个新变量,以便获得正确类型的游标变量。Take note of the following example:请注意以下示例:

    example
    const cursor: AggregationCursor<{ a: number; b: string }> = coll.aggregate([]);
    const projectCursor = cursor.project<{ a: number }>({ _id: 0, a: true });
    const aPropOnlyArray: {a: number}[] = await projectCursor.toArray();
    // or always use chaining and save the final cursor
    const cursor = coll.aggregate().project<{ a: string }>({
      _id: 0,
      a: { $convert: { input: '$a', to: 'string' }
    }});
    

    Type parameters类型参数

    Parameters参数

    Returns返回AggregationCursor<T>

rawListeners

readBufferedDocuments

  • readBufferedDocuments(number?: number): TSchema[]

redact

removeAllListeners

  • removeAllListeners<EventKey>(event?: string | symbol | EventKey): AggregationCursor<TSchema>

removeListener

rewind

  • rewind(): void
  • Rewind this cursor to its uninitialized state. 将游标倒回其未初始化状态。Any options that are present on the cursor will remain in effect. 游标上的任何选项都将保持有效。Iterating this cursor will cause new queries to be sent to the server, even if the resultant data has already been retrieved by this cursor.迭代此游标将导致向服务器发送新的查询,即使结果数据已被此游标检索。

    Returns返回void

setMaxListeners

skip

sort

stream

toArray

  • toArray(): Promise<TSchema[]>
  • toArray(callback: Callback<TSchema[]>): void
  • Returns an array of documents. 返回一个文档数组。The caller is responsible for making sure that there is enough memory to store the results. 调用者负责确保有足够的内存来存储结果。Note that the array only contains partial results when this cursor had been previously accessed. 请注意,当以前访问过该游标时,该数组仅包含部分结果。In that case, cursor.rewind() can be used to reset the cursor.在这种情况下,可以使用cursor.rewind()重置游标。

    Returns返回Promise<TSchema[]>

  • Parameters参数

    Returns返回void

tryNext

  • tryNext(): Promise<null | TSchema>
  • tryNext(callback: Callback<null | TSchema>): void

unwind

withReadConcern

withReadPreference

Static getEventListener

  • getEventListener(emitter: DOMEventTarget | EventEmitter, name: string | symbol): Function[]
  • Returns a list listener for a specific emitter event name.返回特定发射器事件名称的列表侦听器。

    Parameters参数

    • emitter: DOMEventTarget | EventEmitter
    • name: string | symbol

    Returns返回Function[]

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters参数

    • emitter: EventEmitter
    • event: string | symbol

    Returns返回number

Static on

  • on(emitter: EventEmitter, event: string, options?: StaticEventEmitterOptions): AsyncIterableIterator<any>
  • Parameters参数

    • emitter: EventEmitter
    • event: string
    • Optional options: StaticEventEmitterOptions

    Returns返回AsyncIterableIterator<any>

Static once

  • once(emitter: NodeEventTarget, event: string | symbol, options?: StaticEventEmitterOptions): Promise<any[]>
  • once(emitter: DOMEventTarget, event: string, options?: StaticEventEmitterOptions): Promise<any[]>
  • Parameters参数

    • emitter: NodeEventTarget
    • event: string | symbol
    • Optional options: StaticEventEmitterOptions

    Returns返回Promise<any[]>

  • Parameters参数

    • emitter: DOMEventTarget
    • event: string
    • Optional options: StaticEventEmitterOptions

    Returns返回Promise<any[]>

Generated using TypeDoc