new ChangeStream(parent, pipeline, options){ChangeStream}
Creates a new Change Stream instance. Normally created using Collection.watch()
.
Name | Type | Description |
---|---|---|
parent |
MongoClient | Db | Collection |
The parent object that created this change stream |
pipeline |
Array |
An array of aggregation pipeline stages through which to pass change stream documents |
options |
ChangeStreamOptions |
optional
Optional settings |
- Since:
- 3.0.0
Fires:
- ChangeStream#event:close
- ChangeStream#event:change
- ChangeStream#event:end
- ChangeStream#event:error
- ChangeStream#event:resumeTokenChanged
Returns:
ChangeStream instance.Members
-
resumeToken
-
Properties:
Name Type Description resumeToken
ResumeToken The cached resume token that will be used to resume
after the most recently returned change.
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|void}
-
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 change stream closed
-
next(callback){Promise|void}
-
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 Description options
object optional Optional settings.
Name Type Description transform
function 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
-
resumeTokenChanged
-
Emitted each time the change stream stores a new resume token.
Type: