/// <inheritdoc /> public virtual Task <IAsyncCursor <TResult> > WatchAsync <TResult>( PipelineDefinition <ChangeStreamDocument <BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(wrapped.WatchAsync(pipeline, options, cancellationToken)); }
public Task <IChangeStreamCursor <TResult> > WatchAsync <TResult>( PipelineDefinition <ChangeStreamDocument <BsonDocument>, TResult> pipeline, ChangeStreamOptions?options = null, CancellationToken cancellationToken = default) { if (TryGetSession(out IClientSessionHandle? session)) { return(_client.WatchAsync(session, pipeline, options, cancellationToken)); } return(_client.WatchAsync(pipeline, options, cancellationToken)); }
/// <summary> /// Watches changes on all collections in all databases. /// </summary> /// <param name="client">The client.</param> /// <param name="options">The options.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// A change stream. /// </returns> public static Task <IChangeStreamCursor <ChangeStreamDocument <BsonDocument> > > WatchAsync( this IMongoClient client, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(client, nameof(client)); var emptyPipeline = new EmptyPipelineDefinition <ChangeStreamDocument <BsonDocument> >(); return(client.WatchAsync(emptyPipeline, options, cancellationToken)); }
private IAsyncCursor <ChangeStreamDocument <BsonDocument> > Watch(IMongoClient client, BsonDocument test, bool async) { var target = test["target"].AsString; var stages = test["changeStreamPipeline"].AsBsonArray.Cast <BsonDocument>(); var pipeline = new BsonDocumentStagePipelineDefinition <ChangeStreamDocument <BsonDocument>, ChangeStreamDocument <BsonDocument> >(stages); var options = ParseChangeStreamOptions(test["changeStreamOptions"].AsBsonDocument); if (target == "client") { if (async) { return(client.WatchAsync(pipeline, options).GetAwaiter().GetResult()); } else { return(client.Watch(pipeline, options)); } } var database = client.GetDatabase(_databaseName); if (target == "database") { if (async) { return(database.WatchAsync(pipeline, options).GetAwaiter().GetResult()); } else { return(database.Watch(pipeline, options)); } } var collection = database.GetCollection <BsonDocument>(_collectionName); if (target == "collection") { if (async) { return(collection.WatchAsync(pipeline, options).GetAwaiter().GetResult()); } else { return(collection.Watch(pipeline, options)); } } throw new FormatException($"Invalid target: \"{target}\"."); }
public async Task <OperationResult> ExecuteAsync(CancellationToken cancellationToken) { try { var cursor = await _client.WatchAsync(_pipeline, _options, cancellationToken); var changeStream = cursor.ToEnumerable().GetEnumerator(); return(OperationResult.FromChangeStream(changeStream)); } catch (Exception exception) { return(OperationResult.FromException(exception)); } }