Class Watcher<T>
Watcher for subscribing to mongodb change streams.
Inheritance
Inherited Members
Namespace: MongoDB.Entities
Assembly: MongoDB.Entities.dll
Syntax
public class Watcher<T>
where T : IEntity
Type Parameters
Name | Description |
---|---|
T | The type of entity |
Properties
CanRestart
Returns true if watching can be restarted if it was stopped due to an error or invalidate event. Will always return false after cancellation is requested via the cancellation token.
Declaration
public bool CanRestart { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsInitialized
Indicates whether this watcher has already been initialized or not.
Declaration
public bool IsInitialized { get; }
Property Value
Type | Description |
---|---|
Boolean |
Name
The name of this watcher instance
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
String |
ResumeToken
The last resume token received from mongodb server. Can be used to resume watching with .StartWithToken() method.
Declaration
public BsonDocument ResumeToken { get; }
Property Value
Type | Description |
---|---|
BsonDocument |
Methods
ReStart(BsonDocument)
If the watcher stopped due to an error or invalidate event, you can try to restart the watching again with this method.
Declaration
public void ReStart(BsonDocument resumeToken = null)
Parameters
Type | Name | Description |
---|---|---|
BsonDocument | resumeToken | An optional resume token to restart watching with |
Start(EventType, Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>>, Int32, Boolean, Boolean, CancellationToken)
Starts the watcher instance with the supplied parameters
Declaration
public void Start(EventType eventTypes, Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>> filter, int batchSize = 25, bool onlyGetIDs = false, bool autoResume = true, CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
EventType | eventTypes | Type of event to watch for. Specify multiple like: EventType.Created | EventType.Updated | EventType.Deleted |
Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>> | filter | b => b.Eq(d => d.FullDocument.Prop1, "value") |
Int32 | batchSize | The max number of entities to receive for a single event occurence |
Boolean | onlyGetIDs | Set to true if you don't want the complete entity details. All properties except the ID will then be null. |
Boolean | autoResume | Set to false if you'd like to skip the changes that happened while the watching was stopped. This will also make you unable to retrieve a ResumeToken. |
CancellationToken | cancellation | A cancellation token for ending the watching/change stream |
Start(EventType, Expression<Func<T, T>>, Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>>, Int32, Boolean, CancellationToken)
Starts the watcher instance with the supplied parameters. Supports projection.
Declaration
public void Start(EventType eventTypes, Expression<Func<T, T>> projection, Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>> filter, int batchSize = 25, bool autoResume = true, CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
EventType | eventTypes | Type of event to watch for. Specify multiple like: EventType.Created | EventType.Updated | EventType.Deleted |
Expression<Func<T, T>> | projection | A projection expression for the entity |
Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>> | filter | b => b.Eq(d => d.FullDocument.Prop1, "value") |
Int32 | batchSize | The max number of entities to receive for a single event occurence |
Boolean | autoResume | Set to false if you'd like to skip the changes that happened while the watching was stopped. This will also make you unable to retrieve a ResumeToken. |
CancellationToken | cancellation | A cancellation token for ending the watching/change stream |
Start(EventType, Expression<Func<T, T>>, Expression<Func<ChangeStreamDocument<T>, Boolean>>, Int32, Boolean, CancellationToken)
Starts the watcher instance with the supplied parameters. Supports projection.
Declaration
public void Start(EventType eventTypes, Expression<Func<T, T>> projection, Expression<Func<ChangeStreamDocument<T>, bool>> filter = null, int batchSize = 25, bool autoResume = true, CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
EventType | eventTypes | Type of event to watch for. Specify multiple like: EventType.Created | EventType.Updated | EventType.Deleted |
Expression<Func<T, T>> | projection | A projection expression for the entity |
Expression<Func<ChangeStreamDocument<T>, Boolean>> | filter | x => x.FullDocument.Prop1 == "SomeValue" |
Int32 | batchSize | The max number of entities to receive for a single event occurence |
Boolean | autoResume | Set to false if you'd like to skip the changes that happened while the watching was stopped. This will also make you unable to retrieve a ResumeToken. |
CancellationToken | cancellation | A cancellation token for ending the watching/change stream |
Start(EventType, Expression<Func<ChangeStreamDocument<T>, Boolean>>, Int32, Boolean, Boolean, CancellationToken)
Starts the watcher instance with the supplied parameters
Declaration
public void Start(EventType eventTypes, Expression<Func<ChangeStreamDocument<T>, bool>> filter = null, int batchSize = 25, bool onlyGetIDs = false, bool autoResume = true, CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
EventType | eventTypes | Type of event to watch for. Specify multiple like: EventType.Created | EventType.Updated | EventType.Deleted |
Expression<Func<ChangeStreamDocument<T>, Boolean>> | filter | x => x.FullDocument.Prop1 == "SomeValue" |
Int32 | batchSize | The max number of entities to receive for a single event occurence |
Boolean | onlyGetIDs | Set to true if you don't want the complete entity details. All properties except the ID will then be null. |
Boolean | autoResume | Set to false if you'd like to skip the changes that happened while the watching was stopped. This will also make you unable to retrieve a ResumeToken. |
CancellationToken | cancellation | A cancellation token for ending the watching/change stream |
StartWithToken(BsonDocument, EventType, Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>>, Int32, Boolean, CancellationToken)
Starts the watcher instance with the supplied configuration
Declaration
public void StartWithToken(BsonDocument resumeToken, EventType eventTypes, Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>> filter, int batchSize = 25, bool onlyGetIDs = false, CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
BsonDocument | resumeToken | A resume token to start receiving changes after some point back in time |
EventType | eventTypes | Type of event to watch for. Specify multiple like: EventType.Created | EventType.Updated | EventType.Deleted |
Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>> | filter | b => b.Eq(d => d.FullDocument.Prop1, "value") |
Int32 | batchSize | The max number of entities to receive for a single event occurence |
Boolean | onlyGetIDs | Set to true if you don't want the complete entity details. All properties except the ID will then be null. |
CancellationToken | cancellation | A cancellation token for ending the watching/change stream |
StartWithToken(BsonDocument, EventType, Expression<Func<T, T>>, Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>>, Int32, CancellationToken)
Starts the watcher instance with the supplied configuration. Supports projection.
Declaration
public void StartWithToken(BsonDocument resumeToken, EventType eventTypes, Expression<Func<T, T>> projection, Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>> filter, int batchSize = 25, CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
BsonDocument | resumeToken | A resume token to start receiving changes after some point back in time |
EventType | eventTypes | Type of event to watch for. Specify multiple like: EventType.Created | EventType.Updated | EventType.Deleted |
Expression<Func<T, T>> | projection | A projection expression for the entity |
Func<FilterDefinitionBuilder<ChangeStreamDocument<T>>, FilterDefinition<ChangeStreamDocument<T>>> | filter | b => b.Eq(d => d.FullDocument.Prop1, "value") |
Int32 | batchSize | The max number of entities to receive for a single event occurence |
CancellationToken | cancellation | A cancellation token for ending the watching/change stream |
StartWithToken(BsonDocument, EventType, Expression<Func<T, T>>, Expression<Func<ChangeStreamDocument<T>, Boolean>>, Int32, CancellationToken)
Starts the watcher instance with the supplied configuration. Supports projection.
Declaration
public void StartWithToken(BsonDocument resumeToken, EventType eventTypes, Expression<Func<T, T>> projection, Expression<Func<ChangeStreamDocument<T>, bool>> filter = null, int batchSize = 25, CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
BsonDocument | resumeToken | A resume token to start receiving changes after some point back in time |
EventType | eventTypes | Type of event to watch for. Specify multiple like: EventType.Created | EventType.Updated | EventType.Deleted |
Expression<Func<T, T>> | projection | A projection expression for the entity |
Expression<Func<ChangeStreamDocument<T>, Boolean>> | filter | x => x.FullDocument.Prop1 == "SomeValue" |
Int32 | batchSize | The max number of entities to receive for a single event occurence |
CancellationToken | cancellation | A cancellation token for ending the watching/change stream |
StartWithToken(BsonDocument, EventType, Expression<Func<ChangeStreamDocument<T>, Boolean>>, Int32, Boolean, CancellationToken)
Starts the watcher instance with the supplied configuration
Declaration
public void StartWithToken(BsonDocument resumeToken, EventType eventTypes, Expression<Func<ChangeStreamDocument<T>, bool>> filter = null, int batchSize = 25, bool onlyGetIDs = false, CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
BsonDocument | resumeToken | A resume token to start receiving changes after some point back in time |
EventType | eventTypes | Type of event to watch for. Specify multiple like: EventType.Created | EventType.Updated | EventType.Deleted |
Expression<Func<ChangeStreamDocument<T>, Boolean>> | filter | x => x.FullDocument.Prop1 == "SomeValue" |
Int32 | batchSize | The max number of entities to receive for a single event occurence |
Boolean | onlyGetIDs | Set to true if you don't want the complete entity details. All properties except the ID will then be null. |
CancellationToken | cancellation | A cancellation token for ending the watching/change stream |
Events
OnChanges
This event is fired when the desired types of events have occured. Will have a list of 'entities' that was received as input.
Declaration
public event Action<IEnumerable<T>> OnChanges
Event Type
Type | Description |
---|---|
Action<IEnumerable<T>> |
OnChangesAsync
This event is fired when the desired types of events have occured. Will have a list of 'entities' that was received as input.
Declaration
public event AsyncEventHandler<IEnumerable<T>> OnChangesAsync
Event Type
Type | Description |
---|---|
AsyncEventHandler<IEnumerable<T>> |
OnChangesCSD
This event is fired when the desired types of events have occured. Will have a list of 'ChangeStreamDocuments' that was received as input.
Declaration
public event Action<IEnumerable<ChangeStreamDocument<T>>> OnChangesCSD
Event Type
Type | Description |
---|---|
Action<IEnumerable<ChangeStreamDocument<T>>> |
OnChangesCSDAsync
This event is fired when the desired types of events have occured. Will have a list of 'ChangeStreamDocuments' that was received as input.
Declaration
public event AsyncEventHandler<IEnumerable<ChangeStreamDocument<T>>> OnChangesCSDAsync
Event Type
Type | Description |
---|---|
AsyncEventHandler<IEnumerable<ChangeStreamDocument<T>>> |
OnError
This event is fired when an exception is thrown in the change-stream.
Declaration
public event Action<Exception> OnError
Event Type
Type | Description |
---|---|
Action<Exception> |
OnStop
This event is fired when the internal cursor get closed due to an 'invalidate' event or cancellation is requested via the cancellation token.
Declaration
public event Action OnStop
Event Type
Type | Description |
---|---|
Action |