public async Task DistinctAsync_should_execute_the_DistinctOperation() { var fieldName = "a.b"; var filter = new BsonDocument("x", 1); var options = new DistinctOptions <int> { MaxTime = TimeSpan.FromSeconds(20), }; await _subject.DistinctAsync("a.b", filter, options, CancellationToken.None); var call = _operationExecutor.GetReadCall <IReadOnlyList <int> >(); call.Operation.Should().BeOfType <DistinctOperation <int> >(); var operation = (DistinctOperation <int>)call.Operation; operation.CollectionNamespace.FullName.Should().Be("foo.bar"); operation.FieldName.Should().Be(fieldName); operation.Filter.Should().Be(filter); operation.MaxTime.Should().Be(options.MaxTime); }
/// <inheritdoc /> public abstract Task <IAsyncCursor <TField> > DistinctAsync <TField>(FieldDefinition <TDocument, TField> field, FilterDefinition <TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
/// <inheritdoc /> public virtual IAsyncCursor <TField> Distinct <TField>(FieldDefinition <TDocument, TField> field, FilterDefinition <TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); }
/// <summary> /// Gets the distinct values for a specified field. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <typeparam name="TField">The type of the result.</typeparam> /// <param name="collection">The collection.</param> /// <param name="field">The field.</param> /// <param name="filter">The filter.</param> /// <param name="options">The options.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The distinct values for the specified field. /// </returns> public static Task <IAsyncCursor <TField> > DistinctAsync <TDocument, TField>(this IMongoCollection <TDocument> collection, Expression <Func <TDocument, TField> > field, Expression <Func <TDocument, bool> > filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, "collection"); Ensure.IsNotNull(field, "field"); Ensure.IsNotNull(filter, "filter"); return(collection.DistinctAsync <TField>( new ExpressionFieldDefinition <TDocument, TField>(field), new ExpressionFilterDefinition <TDocument>(filter), options, cancellationToken)); }
public override Task <IAsyncCursor <TField> > DistinctAsync <TField>(FieldDefinition <TDocument, TField> field, FilterDefinition <TDocument> filter, DistinctOptions options, CancellationToken cancellationToken) { Ensure.IsNotNull(field, "field"); Ensure.IsNotNull(filter, "filter"); options = options ?? new DistinctOptions(); var renderedField = field.Render(_documentSerializer, _settings.SerializerRegistry); var operation = new DistinctOperation <TField>( _collectionNamespace, renderedField.FieldSerializer, renderedField.FieldName, _messageEncoderSettings) { Filter = filter.Render(_documentSerializer, _settings.SerializerRegistry), MaxTime = options.MaxTime }; return(ExecuteReadOperation(operation, cancellationToken)); }
/// <inheritdoc /> public virtual Task <IAsyncCursor <TField> > DistinctAsync <TField>(IClientSessionHandle session, FieldDefinition <TDocument, TField> field, FilterDefinition <TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); }
public Task <IAsyncCursor <TResult> > DistinctAsync <TResult>(string fieldName, object filter, DistinctOptions <TResult> options, CancellationToken cancellationToken) { Ensure.IsNotNull(fieldName, "fieldName"); Ensure.IsNotNull(filter, "filter"); options = options ?? new DistinctOptions <TResult>(); var resultSerializer = ResolveResultSerializer(options.ResultSerializer); var operation = new DistinctOperation <TResult>( _collectionNamespace, resultSerializer, fieldName, _messageEncoderSettings) { Filter = ConvertFilterToBsonDocument(filter), MaxTime = options.MaxTime }; return(ExecuteReadOperation(operation, cancellationToken)); }
public override Task <IAsyncCursor <TField> > DistinctAsync <TField>(FieldDefinition <TDocument, TField> field, FilterDefinition <TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedCollection.DistinctAsync(field, CombineFilters(filter), options, cancellationToken)); }
public override IAsyncCursor <TField> Distinct <TField>(IClientSessionHandle session, FieldDefinition <TDocument, TField> field, FilterDefinition <TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedCollection.Distinct(session, field, CombineFilters(filter), options, cancellationToken)); }
/// <summary> /// Gets the distinct values for a specified field. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <typeparam name="TField">The type of the result.</typeparam> /// <param name="collection">The collection.</param> /// <param name="field">The field.</param> /// <param name="filter">The filter.</param> /// <param name="options">The options.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The distinct values for the specified field. /// </returns> public static Task <IReadOnlyList <TField> > DistinctAsync <TDocument, TField>(this IMongoCollection <TDocument> collection, Expression <Func <TDocument, TField> > field, Expression <Func <TDocument, bool> > filter, DistinctOptions <TField> options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, "collection"); Ensure.IsNotNull(filter, "filter"); var helper = new BsonSerializationInfoHelper(); helper.RegisterExpressionSerializer(field.Parameters[0], collection.Settings.SerializerRegistry.GetSerializer <TDocument>()); var serializationInfo = helper.GetSerializationInfo(field.Body); options = options ?? new DistinctOptions <TField>(); if (options.ResultSerializer == null) { options.ResultSerializer = (IBsonSerializer <TField>)serializationInfo.Serializer; } return(collection.DistinctAsync(serializationInfo.ElementName, filter, options, cancellationToken)); }
private DistinctOperation <TField> CreateDistinctOperation <TField>(FieldDefinition <TDocument, TField> field, FilterDefinition <TDocument> filter, DistinctOptions options) { var renderedField = field.Render(_documentSerializer, _settings.SerializerRegistry); return(new DistinctOperation <TField>( _collectionNamespace, renderedField.FieldSerializer, renderedField.FieldName, _messageEncoderSettings) { Collation = options.Collation, Filter = filter.Render(_documentSerializer, _settings.SerializerRegistry), MaxTime = options.MaxTime, ReadConcern = _settings.ReadConcern }); }
public override Task <IAsyncCursor <TField> > DistinctAsync <TField>(FieldDefinition <TDocument, TField> field, FilterDefinition <TDocument> filter, DistinctOptions options, CancellationToken cancellationToken) { Ensure.IsNotNull(field, nameof(field)); Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new DistinctOptions(); var operation = CreateDistinctOperation(field, filter, options); return(ExecuteReadOperationAsync(operation, cancellationToken)); }