new CommandCursor(){CommandCursor}
Creates a new Command Cursor instance (INTERNAL TYPE, do not instantiate directly)
Fires:
- CommandCursor#event:data
- CommandCursor#event:end
- CommandCursor#event:close
- CommandCursor#event:readable
Returns:
CommandCursor instance.Extends
Methods
-
batchSize(value){CommandCursor}
-
Set the batch size for the cursor.
Name Type Description valuenumber The batchSize for the cursor.
Throws:
-
clone(){CommandCursor}
-
Clone the cursor
-
close(callback){Promise}
-
Close the cursor, sending a KillCursor command and emitting close.
Name Type Description callbackCommandCursor~resultCallback optional The result callback.
Returns:
Promise if no callback passed
-
each(callback){null}
-
Iterates over all the documents for this cursor. As with {cursor.toArray},
not all of the elements will be iterated if this cursor had been previouly accessed.
In that case, {cursor.rewind} can be used to reset the cursor. However, unlike
{cursor.toArray}, the cursor will only hold a maximum of batch size elements
at any given time if batch size is specified. Otherwise, the caller is responsible
for making sure that the entire result can fit the memory.Name Type Description callbackCommandCursor~resultCallback The result callback.
Throws:
-
hasNext(callback){Promise}
-
Check if there is any document still available in the cursor
Name Type Description callbackCommandCursor~resultCallback optional The result callback.
Throws:
Returns:
Promise if no callback passed
-
isClosed(){boolean}
-
Is the cursor closed
-
maxTimeMS(value){CommandCursor}
-
Add a maxTimeMS stage to the aggregation pipeline
Name Type Description valuenumber The state maxTimeMS value.
-
next(callback){Promise}
-
Get the next available document from the cursor, returns null if no more documents are available.
Name Type Description callbackCommandCursor~resultCallback optional The result callback.
Throws:
Returns:
Promise if no callback passed
-
inherited pause(){null}
-
This method will cause a stream in flowing-mode to stop emitting data events. Any data that becomes available will remain in the internal buffer.
-
inherited pipe(destination, options){null}
-
This method pulls all the data out of a readable stream, and writes it to the supplied destination, automatically managing the flow so that the destination is not overwhelmed by a fast readable stream.
Name Type Description destinationWritable The destination for writing data
optionsobject optional Pipe options
-
inherited read(size){String|Buffer|null}
-
The read() method pulls some data out of the internal buffer and returns it. If there is no data available, then it will return null.
Name Type Description sizenumber Optional argument to specify how much data to read.
-
inherited resume(){null}
-
This method will cause the readable stream to resume emitting data events.
-
rewind(){CommandCursor}
-
Resets the cursor
-
inherited setEncoding(encoding){null}
-
Call this function to cause the stream to return strings of the specified encoding instead of Buffer objects.
Name Type Description encodingstring The encoding to use.
-
setReadPreference(readPreference){Cursor}
-
Set the ReadPreference for the cursor.
Name Type Description readPreferencestring | ReadPreference The new read preference for the cursor.
Throws:
-
toArray(callback){Promise}
-
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 contain partial
results when this cursor had been previouly accessed.Name Type Description callbackCommandCursor~toArrayResultCallback optional The result callback.
Throws:
Returns:
Promise if no callback passed
-
inherited unpipe(destination){null}
-
This method will remove the hooks set up for a previous pipe() call.
Name Type Description destinationWritable optional The destination for writing data
-
inherited unshift(chunk){null}
-
This is useful in certain cases where a stream is being consumed by a parser, which needs to "un-consume" some data that it has optimistically pulled out of the source, so that the stream can be passed on to some other party.
Name Type Description chunkBuffer | string Chunk of data to unshift onto the read queue.
-
inherited wrap(stream){null}
-
Versions of Node prior to v0.10 had streams that did not implement the entire Streams API as it is today. (See "Compatibility" below for more information.)
Name Type Description streamStream An "old style" readable stream.
Type Definitions
-
endCallback(error)
-
The callback error format for the forEach iterator method
Name Type Description errorMongoError An error instance representing the error during the execution.
-
iteratorCallback(doc)
-
The callback format for the forEach iterator method
Name Type Description docObject An emitted document for the iterator
-
resultCallback(error, result)
-
The callback format for results
Name Type Description errorMongoError An error instance representing the error during the execution.
resultobject | null The result object if the command was executed successfully.
-
toArrayResultCallback(error, documents)
-
The callback format for results
Name Type Description errorMongoError An error instance representing the error during the execution.
documentsArray.<object> All the documents the satisfy the cursor.
Events
-
close
-
CommandCursor stream close event
Type:
- null
-
data
-
CommandCursor stream data event, fired for each document in the cursor.
Type:
- object
-
CommandCursor stream end event
Type:
- null
-
readable
-
CommandCursor stream readable event
Type:
- null