/// <inheritdoc /> public virtual Task <IAsyncCursor <TResult> > WatchAsync <TResult>( IClientSessionHandle session, PipelineDefinition <ChangeStreamDocument <TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); // implemented by subclasses }
// public static methods public static ChangeStreamOperation <TResult> CreateChangeStreamOperation <TResult>( PipelineDefinition <ChangeStreamDocument <BsonDocument>, TResult> pipeline, ChangeStreamOptions options, ReadConcern readConcern, MessageEncoderSettings messageEncoderSettings, bool retryRequested) { return(CreateChangeStreamOperation(pipeline, LinqProvider.V2, options, readConcern, messageEncoderSettings, retryRequested)); }
/// <summary> /// Watches changes on all collection in a database. /// </summary> /// <param name="database">The database.</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 IMongoDatabase database, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(database, nameof(database)); var emptyPipeline = new EmptyPipelineDefinition <ChangeStreamDocument <BsonDocument> >(); return(database.WatchAsync(emptyPipeline, 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 IAsyncCursor <ChangeStreamDocument <BsonDocument> > Watch( this IMongoClient client, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(client, nameof(client)); var emptyPipeline = new EmptyPipelineDefinition <ChangeStreamDocument <BsonDocument> >(); return(client.Watch(emptyPipeline, options, cancellationToken)); }
private ChangeStreamOperation <TResult> CreateChangeStreamOperation <TResult>( PipelineDefinition <ChangeStreamDocument <BsonDocument>, TResult> pipeline, ChangeStreamOptions options) { return(ChangeStreamHelper.CreateChangeStreamOperation( pipeline, options, _settings.ReadConcern, GetMessageEncoderSettings(), _settings.RetryReads)); }
public static ChangeStreamOperation <TResult> CreateChangeStreamOperation <TResult, TDocument>( IMongoCollection <TDocument> collection, PipelineDefinition <ChangeStreamDocument <TDocument>, TResult> pipeline, IBsonSerializer <TDocument> documentSerializer, ChangeStreamOptions options, ReadConcern readConcern, MessageEncoderSettings messageEncoderSettings, bool retryRequested) { return(CreateChangeStreamOperation(collection, pipeline, documentSerializer, LinqProvider.V2, options, readConcern, messageEncoderSettings, retryRequested)); }
public override Task <IChangeStreamCursor <TResult> > WatchAsync <TResult>( IClientSessionHandle session, PipelineDefinition <ChangeStreamDocument <BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(pipeline, nameof(pipeline)); var operation = CreateChangeStreamOperation(pipeline, options); return(ExecuteReadOperationAsync(session, operation, cancellationToken)); }
/// <summary> /// Watches changes on all collection in a database. /// </summary> /// <param name="database">The database.</param> /// <param name="session">The session.</param> /// <param name="options">The options.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// A change stream. /// </returns> public static IChangeStreamCursor <ChangeStreamDocument <BsonDocument> > Watch( this IMongoDatabase database, IClientSessionHandle session, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(database, nameof(database)); Ensure.IsNotNull(session, nameof(session)); var emptyPipeline = new EmptyPipelineDefinition <ChangeStreamDocument <BsonDocument> >(); return(database.Watch(session, emptyPipeline, options, cancellationToken)); }
/// <summary> /// Watches changes on all collections in all databases. /// </summary> /// <param name="client">The client.</param> /// <param name="session">The session.</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, IClientSessionHandle session, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(client, nameof(client)); Ensure.IsNotNull(session, nameof(session)); var emptyPipeline = new EmptyPipelineDefinition <ChangeStreamDocument <BsonDocument> >(); return(client.WatchAsync(session, emptyPipeline, options, cancellationToken)); }
private static void SetOperationOptions <TResult>( ChangeStreamOperation <TResult> operation, ChangeStreamOptions options, ReadConcern readConcern) { options = options ?? new ChangeStreamOptions(); operation.BatchSize = options.BatchSize; operation.Collation = options.Collation; operation.FullDocument = options.FullDocument; operation.MaxAwaitTime = options.MaxAwaitTime; operation.ReadConcern = readConcern; operation.ResumeAfter = options.ResumeAfter; operation.StartAtOperationTime = options.StartAtOperationTime; }
// public static methods public static ChangeStreamOperation <TResult> CreateChangeStreamOperation <TResult>( PipelineDefinition <ChangeStreamDocument <BsonDocument>, TResult> pipeline, ChangeStreamOptions options, ReadConcern readConcern, MessageEncoderSettings messageEncoderSettings) { var renderedPipeline = RenderPipeline(pipeline, BsonDocumentSerializer.Instance); var operation = new ChangeStreamOperation <TResult>( renderedPipeline.Documents, renderedPipeline.OutputSerializer, messageEncoderSettings); SetOperationOptions(operation, options, readConcern); return(operation); }
public static ChangeStreamOperation <TResult> CreateChangeStreamOperation <TResult, TDocument>( IMongoCollection <TDocument> collection, PipelineDefinition <ChangeStreamDocument <TDocument>, TResult> pipeline, IBsonSerializer <TDocument> documentSerializer, ChangeStreamOptions options, ReadConcern readConcern, MessageEncoderSettings messageEncoderSettings) { var renderedPipeline = RenderPipeline(pipeline, documentSerializer); var operation = new ChangeStreamOperation <TResult>( collection.CollectionNamespace, renderedPipeline.Documents, renderedPipeline.OutputSerializer, messageEncoderSettings); SetOperationOptions(operation, options, readConcern); return(operation); }
public static ChangeStreamOperation <TResult> CreateChangeStreamOperation <TResult>( IMongoDatabase database, PipelineDefinition <ChangeStreamDocument <BsonDocument>, TResult> pipeline, ChangeStreamOptions options, ReadConcern readConcern, MessageEncoderSettings messageEncoderSettings, bool retryRequested) { var renderedPipeline = RenderPipeline(pipeline, BsonDocumentSerializer.Instance); var operation = new ChangeStreamOperation <TResult>( database.DatabaseNamespace, renderedPipeline.Documents, renderedPipeline.OutputSerializer, messageEncoderSettings) { RetryRequested = retryRequested }; SetOperationOptions(operation, options, readConcern); return(operation); }
public void Watch_should_invoke_the_correct_operation( [Values(false, true)] bool usingSession, [Values(false, true)] bool async) { var session = CreateSession(usingSession); var pipeline = new EmptyPipelineDefinition <ChangeStreamDocument <BsonDocument> >().Limit(1); var options = new ChangeStreamOptions { BatchSize = 123, Collation = new Collation("en-us"), FullDocument = ChangeStreamFullDocumentOption.UpdateLookup, MaxAwaitTime = TimeSpan.FromSeconds(123), ResumeAfter = new BsonDocument(), StartAfter = new BsonDocument(), StartAtOperationTime = new BsonTimestamp(1, 2) }; var cancellationToken = new CancellationTokenSource().Token; var renderedPipeline = new[] { BsonDocument.Parse("{ $limit : 1 }") }; if (usingSession) { if (async) { _subject.WatchAsync(session, pipeline, options, cancellationToken).GetAwaiter().GetResult(); } else { _subject.Watch(session, pipeline, options, cancellationToken); } } else { if (async) { _subject.WatchAsync(pipeline, options, cancellationToken).GetAwaiter().GetResult(); } else { _subject.Watch(pipeline, options, cancellationToken); } } var call = _operationExecutor.GetReadCall <IChangeStreamCursor <ChangeStreamDocument <BsonDocument> > >(); if (usingSession) { call.SessionId.Should().BeSameAs(session.ServerSession.Id); } else { call.UsedImplicitSession.Should().BeTrue(); } call.CancellationToken.Should().Be(cancellationToken); var changeStreamOperation = call.Operation.Should().BeOfType <ChangeStreamOperation <ChangeStreamDocument <BsonDocument> > >().Subject; changeStreamOperation.BatchSize.Should().Be(options.BatchSize); changeStreamOperation.Collation.Should().BeSameAs(options.Collation); changeStreamOperation.CollectionNamespace.Should().BeNull(); changeStreamOperation.DatabaseNamespace.Should().Be(_subject.DatabaseNamespace); changeStreamOperation.FullDocument.Should().Be(options.FullDocument); changeStreamOperation.MaxAwaitTime.Should().Be(options.MaxAwaitTime); changeStreamOperation.MessageEncoderSettings.Should().NotBeNull(); changeStreamOperation.Pipeline.Should().Equal(renderedPipeline); changeStreamOperation.ReadConcern.Should().Be(_subject.Settings.ReadConcern); changeStreamOperation.ResultSerializer.Should().BeOfType <ChangeStreamDocumentSerializer <BsonDocument> >(); changeStreamOperation.ResumeAfter.Should().Be(options.ResumeAfter); changeStreamOperation.RetryRequested.Should().BeTrue(); changeStreamOperation.StartAfter.Should().Be(options.StartAfter); changeStreamOperation.StartAtOperationTime.Should().Be(options.StartAtOperationTime); }