public override Task <long> CountAsync(FilterDefinition <TDocument> filter, CountOptions options, CancellationToken cancellationToken) { Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new CountOptions(); var operation = CreateCountOperation(filter, options); return(ExecuteReadOperationAsync(operation, cancellationToken)); }
/// <summary> /// Counts the asynchronous. /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public Task <long> CountAsync(CancellationToken cancellationToken) { BsonValue hint; _options.Modifiers.TryGetValue("$hint", out hint); var options = new CountOptions { Hint = hint, Limit = _options.Limit, MaxTime = _options.MaxTime, Skip = _options.Skip }; return(_collection.CountAsync(_filter, options, cancellationToken)); }
public override Task <long> CountAsync(FilterDefinition <TDocument> filter, CountOptions options, CancellationToken cancellationToken) { Ensure.IsNotNull(filter, "filter"); options = options ?? new CountOptions(); var operation = new CountOperation(_collectionNamespace, _messageEncoderSettings) { Filter = filter.Render(_documentSerializer, _settings.SerializerRegistry), Hint = options.Hint, Limit = options.Limit, MaxTime = options.MaxTime, Skip = options.Skip }; return(ExecuteReadOperation(operation, cancellationToken)); }
public Task <long> CountAsync(object filter, CountOptions options, CancellationToken cancellationToken) { Ensure.IsNotNull(filter, "filter"); options = options ?? new CountOptions(); var operation = new CountOperation(_collectionNamespace, _messageEncoderSettings) { Filter = ConvertFilterToBsonDocument(filter), Hint = options.Hint is string?BsonValue.Create((string)options.Hint) : ConvertToBsonDocument(options.Hint), Limit = options.Limit, MaxTime = options.MaxTime, Skip = options.Skip }; return(ExecuteReadOperation(operation, cancellationToken)); }
public async Task CountAsync_should_execute_the_CountOperation() { var filter = new BsonDocument("x", 1); var options = new CountOptions { Hint = "funny", Limit = 10, MaxTime = TimeSpan.FromSeconds(20), Skip = 30 }; await _subject.CountAsync(filter, options, CancellationToken.None); var call = _operationExecutor.GetReadCall <long>(); call.Operation.Should().BeOfType <CountOperation>(); var operation = (CountOperation)call.Operation; operation.CollectionNamespace.FullName.Should().Be("foo.bar"); operation.Filter.Should().Be(filter); operation.Hint.Should().Be((string)options.Hint); operation.Limit.Should().Be(options.Limit); operation.MaxTime.Should().Be(options.MaxTime); operation.Skip.Should().Be(options.Skip); }
/// <inheritdoc /> public abstract Task <long> CountAsync(FilterDefinition <TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
/// <inheritdoc /> public virtual long Count(FilterDefinition <TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); }
/// <summary> /// Counts the number of documents in the collection. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <param name="collection">The collection.</param> /// <param name="filter">The filter.</param> /// <param name="options">The options.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The number of documents in the collection. /// </returns> public static Task <long> CountAsync <TDocument>(this IMongoCollection <TDocument> collection, Expression <Func <TDocument, bool> > filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, "collection"); Ensure.IsNotNull(filter, "filter"); return(collection.CountAsync(new ExpressionFilterDefinition <TDocument>(filter), options, cancellationToken)); }
/// <inheritdoc /> public virtual Task <long> CountDocumentsAsync(IClientSessionHandle session, FilterDefinition <TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); }
public override long Count(FilterDefinition <TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedCollection.Count(CombineFilters(filter), options, cancellationToken)); }
public override Task <long> CountDocumentsAsync(IClientSessionHandle session, FilterDefinition <TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedCollection.CountDocumentsAsync(session, CombineFilters(filter), options, cancellationToken)); }
private CountOperation CreateCountOperation(FilterDefinition <TDocument> filter, CountOptions options) { return(new CountOperation(_collectionNamespace, _messageEncoderSettings) { Collation = options.Collation, Filter = filter.Render(_documentSerializer, _settings.SerializerRegistry), Hint = options.Hint, Limit = options.Limit, MaxTime = options.MaxTime, ReadConcern = _settings.ReadConcern, Skip = options.Skip }); }