/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver.Core.Misc;
using MongoDB.Driver.Linq;
namespace MongoDB.Driver
{
///
/// Extension methods for .
///
public static class IMongoCollectionExtensions
{
///
/// Begins a fluent aggregation interface.
///
/// The type of the document.
/// The collection.
/// The options.
///
/// A fluent aggregate interface.
///
public static IAggregateFluent Aggregate(this IMongoCollection collection, AggregateOptions options = null)
{
var emptyPipeline = new EmptyPipelineDefinition(collection.DocumentSerializer);
return new AggregateFluent(null, collection, emptyPipeline, options ?? new AggregateOptions());
}
///
/// Begins a fluent aggregation interface.
///
/// The type of the document.
/// The collection.
/// The session.
/// The options.
///
/// A fluent aggregate interface.
///
public static IAggregateFluent Aggregate(this IMongoCollection collection, IClientSessionHandle session, AggregateOptions options = null)
{
Ensure.IsNotNull(session, nameof(session));
var emptyPipeline = new EmptyPipelineDefinition(collection.DocumentSerializer);
return new AggregateFluent(session, collection, emptyPipeline, options ?? new AggregateOptions());
}
///
/// Creates a queryable source of documents.
///
/// The type of the document.
/// The collection.
/// The aggregate options
/// A queryable source of documents.
public static IMongoQueryable AsQueryable(this IMongoCollection collection, AggregateOptions aggregateOptions = null)
{
Ensure.IsNotNull(collection, nameof(collection));
aggregateOptions = aggregateOptions ?? new AggregateOptions();
var provider = new MongoQueryProviderImpl(collection, aggregateOptions);
return new MongoQueryableImpl(provider);
}
///
/// Counts the number of documents in the collection.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The number of documents in the collection.
///
[Obsolete("Use CountDocuments or EstimatedDocumentCount instead.")]
public static long Count(this IMongoCollection collection, Expression> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.Count(new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Counts the number of documents in the collection.
///
/// The type of the document.
/// The session.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The number of documents in the collection.
///
[Obsolete("Use CountDocuments or EstimatedDocumentCount instead.")]
public static long Count(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.Count(session, new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Counts the number of documents in the collection.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The number of documents in the collection.
///
[Obsolete("Use CountDocumentsAsync or EstimatedDocumentCountAsync instead.")]
public static Task CountAsync(this IMongoCollection collection, Expression> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.CountAsync(new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Counts the number of documents in the collection.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The number of documents in the collection.
///
[Obsolete("Use CountDocumentsAsync or EstimatedDocumentCountAsync instead.")]
public static Task CountAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.CountAsync(session, new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Counts the number of documents in the collection.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The number of documents in the collection.
///
public static long CountDocuments(this IMongoCollection collection, Expression> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.CountDocuments(new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Counts the number of documents in the collection.
///
/// The type of the document.
/// The session.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The number of documents in the collection.
///
public static long CountDocuments(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.CountDocuments(session, new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Counts the number of documents in the collection.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The number of documents in the collection.
///
public static Task CountDocumentsAsync(this IMongoCollection collection, Expression> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.CountDocumentsAsync(new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Counts the number of documents in the collection.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The number of documents in the collection.
///
public static Task CountDocumentsAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.CountDocumentsAsync(session, new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Deletes multiple documents.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static DeleteResult DeleteMany(this IMongoCollection collection, Expression> filter, CancellationToken cancellationToken = default(CancellationToken))
{
return collection.DeleteMany(new ExpressionFilterDefinition(filter), cancellationToken);
}
///
/// Deletes multiple documents.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static DeleteResult DeleteMany(this IMongoCollection collection, Expression> filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DeleteMany(new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Deletes multiple documents.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static DeleteResult DeleteMany(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, DeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DeleteMany(session, new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Deletes multiple documents.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static Task DeleteManyAsync(this IMongoCollection collection, Expression> filter, CancellationToken cancellationToken = default(CancellationToken))
{
return collection.DeleteManyAsync(new ExpressionFilterDefinition(filter), cancellationToken);
}
///
/// Deletes multiple documents.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static Task DeleteManyAsync(this IMongoCollection collection, Expression> filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DeleteManyAsync(new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Deletes multiple documents.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static Task DeleteManyAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, DeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DeleteManyAsync(session, new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Deletes a single document.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static DeleteResult DeleteOne(this IMongoCollection collection, Expression> filter, CancellationToken cancellationToken = default(CancellationToken))
{
return collection.DeleteOne(new ExpressionFilterDefinition(filter), cancellationToken);
}
///
/// Deletes a single document.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static DeleteResult DeleteOne(this IMongoCollection collection, Expression> filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DeleteOne(new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Deletes a single document.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static DeleteResult DeleteOne(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, DeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DeleteOne(session, new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Deletes a single document.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static Task DeleteOneAsync(this IMongoCollection collection, Expression> filter, CancellationToken cancellationToken = default(CancellationToken))
{
return collection.DeleteOneAsync(new ExpressionFilterDefinition(filter), cancellationToken);
}
///
/// Deletes a single document.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static Task DeleteOneAsync(this IMongoCollection collection, Expression> filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DeleteOneAsync(new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Deletes a single document.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The result of the delete operation.
///
public static Task DeleteOneAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, DeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DeleteOneAsync(session, new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static IAsyncCursor Distinct(this IMongoCollection collection, Expression> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.Distinct(
new ExpressionFieldDefinition(field),
filter,
options,
cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static IAsyncCursor Distinct(this IMongoCollection collection, FieldDefinition field, Expression> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.Distinct(
field,
new ExpressionFilterDefinition(filter),
options,
cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static IAsyncCursor Distinct(this IMongoCollection collection, Expression> field, Expression> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.Distinct(
new ExpressionFieldDefinition(field),
new ExpressionFilterDefinition(filter),
options,
cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The session.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static IAsyncCursor Distinct(this IMongoCollection collection, IClientSessionHandle session, Expression> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.Distinct(
session,
new ExpressionFieldDefinition(field),
filter,
options,
cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The session.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static IAsyncCursor Distinct(this IMongoCollection collection, IClientSessionHandle session, FieldDefinition field, Expression> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.Distinct(
session,
field,
new ExpressionFilterDefinition(filter),
options,
cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The session.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static IAsyncCursor Distinct(this IMongoCollection collection, IClientSessionHandle session, Expression> field, Expression> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.Distinct(
session,
new ExpressionFieldDefinition(field),
new ExpressionFilterDefinition(filter),
options,
cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static Task> DistinctAsync(this IMongoCollection collection, Expression> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DistinctAsync(
new ExpressionFieldDefinition(field),
filter,
options,
cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static Task> DistinctAsync(this IMongoCollection collection, FieldDefinition field, Expression> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DistinctAsync(
field,
new ExpressionFilterDefinition(filter),
options,
cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static Task> DistinctAsync(this IMongoCollection collection, Expression> field, Expression> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DistinctAsync(
new ExpressionFieldDefinition(field),
new ExpressionFilterDefinition(filter),
options,
cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The session.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static Task> DistinctAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DistinctAsync(
session,
new ExpressionFieldDefinition(field),
filter,
options,
cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The session.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static Task> DistinctAsync(this IMongoCollection collection, IClientSessionHandle session, FieldDefinition field, Expression> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DistinctAsync(
session,
field,
new ExpressionFilterDefinition(filter),
options,
cancellationToken);
}
///
/// Gets the distinct values for a specified field.
///
/// The type of the document.
/// The type of the result.
/// The collection.
/// The session.
/// The field.
/// The filter.
/// The options.
/// The cancellation token.
///
/// The distinct values for the specified field.
///
public static Task> DistinctAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> field, Expression> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(field, nameof(field));
Ensure.IsNotNull(filter, nameof(filter));
return collection.DistinctAsync(
session,
new ExpressionFieldDefinition(field),
new ExpressionFilterDefinition(filter),
options,
cancellationToken);
}
///
/// Begins a fluent find interface.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
///
/// A fluent find interface.
///
public static IFindFluent Find(this IMongoCollection collection, FilterDefinition filter, FindOptions options = null)
{
return FindHelper(null, collection, filter, options);
}
///
/// Begins a fluent find interface.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
///
/// A fluent find interface.
///
public static IFindFluent Find(this IMongoCollection collection, IClientSessionHandle session, FilterDefinition filter, FindOptions options = null)
{
Ensure.IsNotNull(session, nameof(session));
return FindHelper(session, collection, filter, options);
}
private static IFindFluent FindHelper(IClientSessionHandle session, IMongoCollection collection, FilterDefinition filter, FindOptions options)
{
FindOptions genericOptions;
if (options == null)
{
genericOptions = new FindOptions();
}
else
{
genericOptions = new FindOptions
{
AllowPartialResults = options.AllowPartialResults,
BatchSize = options.BatchSize,
Collation = options.Collation,
Comment = options.Comment,
CursorType = options.CursorType,
MaxAwaitTime = options.MaxAwaitTime,
MaxTime = options.MaxTime,
Modifiers = options.Modifiers,
NoCursorTimeout = options.NoCursorTimeout,
OplogReplay = options.OplogReplay
};
}
return new FindFluent(session, collection, filter, genericOptions);
}
///
/// Begins a fluent find interface.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
///
/// A fluent interface.
///
public static IFindFluent Find(this IMongoCollection collection, Expression> filter, FindOptions options = null)
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.Find(new ExpressionFilterDefinition(filter), options);
}
///
/// Begins a fluent find interface.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
///
/// A fluent interface.
///
public static IFindFluent Find(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, FindOptions options = null)
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.Find(session, new ExpressionFilterDefinition(filter), options);
}
///
/// Finds the documents matching the filter.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
/// A Task whose result is a cursor.
public static IAsyncCursor FindSync(this IMongoCollection collection, FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.FindSync(filter, options, cancellationToken);
}
///
/// Finds the documents matching the filter.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
/// A Task whose result is a cursor.
public static IAsyncCursor FindSync(this IMongoCollection collection, Expression> filter, FindOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.FindSync(new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Finds the documents matching the filter.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
/// The cancellation token.
///
/// A Task whose result is a cursor.
///
public static IAsyncCursor FindSync(this IMongoCollection collection, IClientSessionHandle session, FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.FindSync(session, filter, options, cancellationToken);
}
///
/// Finds the documents matching the filter.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
/// The cancellation token.
///
/// A Task whose result is a cursor.
///
public static IAsyncCursor FindSync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, FindOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.FindSync(session, new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Finds the documents matching the filter.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
/// A Task whose result is a cursor.
public static Task> FindAsync(this IMongoCollection collection, FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.FindAsync(filter, options, cancellationToken);
}
///
/// Finds the documents matching the filter.
///
/// The type of the document.
/// The collection.
/// The filter.
/// The options.
/// The cancellation token.
/// A Task whose result is a cursor.
public static Task> FindAsync(this IMongoCollection collection, Expression> filter, FindOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(filter, nameof(filter));
return collection.FindAsync(new ExpressionFilterDefinition(filter), options, cancellationToken);
}
///
/// Finds the documents matching the filter.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
/// The cancellation token.
///
/// A Task whose result is a cursor.
///
public static Task> FindAsync(this IMongoCollection collection, IClientSessionHandle session, FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
{
Ensure.IsNotNull(collection, nameof(collection));
Ensure.IsNotNull(session, nameof(session));
Ensure.IsNotNull(filter, nameof(filter));
return collection.FindAsync(session, filter, options, cancellationToken);
}
///
/// Finds the documents matching the filter.
///
/// The type of the document.
/// The collection.
/// The session.
/// The filter.
/// The options.
/// The cancellation token.
///
/// A Task whose result is a cursor.
///
public static Task> FindAsync(this IMongoCollection