new ChangeStream(changeDomain, pipeline, options){ChangeStream}
Creates a new Change Stream instance. Normally created using Collection.watch()
.
Name | Type | Default | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
changeDomain |
Db | Collection |
The collection against which to create the change stream |
|||||||||||||||||||||||||||||
pipeline |
Array |
An array of aggregation pipeline stages through which to pass change stream documents |
|||||||||||||||||||||||||||||
options |
object | null |
optional
Optional settings
|
- Since:
- 3.0.0
Fires:
Returns:
ChangeStream instance.Methods
-
close(callback){Promise}
-
Close the Change Stream
Name Type Description callback
ChangeStream~resultCallback optional The result callback.
Returns:
Promise if no callback passed
-
hasNext(callback){Promise}
-
Check if there is any document still available in the Change Stream
Name Type Description callback
ChangeStream~resultCallback optional The result callback.
Throws:
Returns:
Promise if no callback passed
-
isClosed(){boolean}
-
Is the cursor closed
-
next(callback){Promise}
-
Get the next available document from the Change Stream, returns null if no more documents are available.
Name Type Description callback
ChangeStream~resultCallback optional The result callback.
Throws:
Returns:
Promise if no callback passed
-
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.
-
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 destination
Writable The destination for writing data
options
object optional -
resume(){null}
-
This method will cause the readable stream to resume emitting data events.
-
stream(options){Cursor}
-
Return a modified Readable stream including a possible transform method.
Name Type Default Description options
object null optional Optional settings.
Name Type Default Description transform
function null optional A transformation method applied to each document emitted by the stream.
-
unpipe(destination){null}
-
This method will remove the hooks set up for a previous pipe() call.
Name Type Description destination
Writable optional The destination for writing data
Type Definitions
-
resultCallback(error, result)
-
The callback format for results
Name Type Description error
MongoError An error instance representing the error during the execution.
result
object | null The result object if the command was executed successfully.
Events
-
change
-
Fired for each new matching change in the specified namespace. Attaching a
change
event listener to a Change Stream will switch the stream into flowing mode. Data will then be passed as soon as it is available.Type:
- object
-
close
-
Change stream close event
Type:
- null
-
Change stream end event
Type:
- null
-
error
-
Fired when the stream encounters an error.
Type:
- Error