/* 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 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.FindAsync(session, new ExpressionFilterDefinition(filter), options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The options. /// The cancellation token. /// /// The deleted document if one was deleted. /// public static TDocument FindOneAndDelete(this IMongoCollection collection, FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDelete(filter, options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The options. /// The cancellation token. /// /// The deleted document if one was deleted. /// public static TDocument FindOneAndDelete(this IMongoCollection collection, Expression> filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDelete(new ExpressionFilterDefinition(filter), options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The filter. /// The options. /// The cancellation token. /// /// The returned document. /// public static TProjection FindOneAndDelete(this IMongoCollection collection, Expression> filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDelete(new ExpressionFilterDefinition(filter), options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The options. /// The cancellation token. /// /// The deleted document if one was deleted. /// public static TDocument FindOneAndDelete(this IMongoCollection collection, IClientSessionHandle session, FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDelete(session, filter, options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The options. /// The cancellation token. /// /// The deleted document if one was deleted. /// public static TDocument FindOneAndDelete(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDelete(session, new ExpressionFilterDefinition(filter), options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The session. /// The filter. /// The options. /// The cancellation token. /// /// The returned document. /// public static TProjection FindOneAndDelete(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDelete(session, new ExpressionFilterDefinition(filter), options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The options. /// The cancellation token. /// /// The deleted document if one was deleted. /// public static Task FindOneAndDeleteAsync(this IMongoCollection collection, FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDeleteAsync(filter, options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The options. /// The cancellation token. /// /// The deleted document if one was deleted. /// public static Task FindOneAndDeleteAsync(this IMongoCollection collection, Expression> filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDeleteAsync(new ExpressionFilterDefinition(filter), options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The filter. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndDeleteAsync(this IMongoCollection collection, Expression> filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDeleteAsync(new ExpressionFilterDefinition(filter), options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The options. /// The cancellation token. /// /// The deleted document if one was deleted. /// public static Task FindOneAndDeleteAsync(this IMongoCollection collection, IClientSessionHandle session, FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDeleteAsync(session, filter, options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The options. /// The cancellation token. /// /// The deleted document if one was deleted. /// public static Task FindOneAndDeleteAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDeleteAsync(session, new ExpressionFilterDefinition(filter), options, cancellationToken); } /// /// Finds a single document and deletes it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The session. /// The filter. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndDeleteAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndDeleteAsync(session, new ExpressionFilterDefinition(filter), options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static TDocument FindOneAndReplace(this IMongoCollection collection, FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplace(filter, replacement, options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static TDocument FindOneAndReplace(this IMongoCollection collection, Expression> filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplace(new ExpressionFilterDefinition(filter), replacement, options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static TProjection FindOneAndReplace(this IMongoCollection collection, Expression> filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplace(filter, replacement, options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static TDocument FindOneAndReplace(this IMongoCollection collection, IClientSessionHandle session, FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplace(session, filter, replacement, options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static TDocument FindOneAndReplace(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplace(session, new ExpressionFilterDefinition(filter), replacement, options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The session. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static TProjection FindOneAndReplace(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplace(session, filter, replacement, options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndReplaceAsync(this IMongoCollection collection, FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplaceAsync(filter, replacement, options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndReplaceAsync(this IMongoCollection collection, Expression> filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplaceAsync(new ExpressionFilterDefinition(filter), replacement, options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndReplaceAsync(this IMongoCollection collection, Expression> filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplaceAsync(filter, replacement, options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndReplaceAsync(this IMongoCollection collection, IClientSessionHandle session, FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplaceAsync(session, filter, replacement, options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The session. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndReplaceAsync(this IMongoCollection collection, Expression> filter, IClientSessionHandle session, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplaceAsync(session, new ExpressionFilterDefinition(filter), replacement, options, cancellationToken); } /// /// Finds a single document and replaces it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The session. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndReplaceAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.FindOneAndReplaceAsync(session, filter, replacement, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static TDocument FindOneAndUpdate(this IMongoCollection collection, FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdate( filter, update, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static TDocument FindOneAndUpdate(this IMongoCollection collection, Expression> filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdate( new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static TProjection FindOneAndUpdate(this IMongoCollection collection, Expression> filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdate(new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static TDocument FindOneAndUpdate(this IMongoCollection collection, IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdate( session, filter, update, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static TDocument FindOneAndUpdate(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdate( session, new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The session. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static TProjection FindOneAndUpdate(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdate(session, new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndUpdateAsync(this IMongoCollection collection, FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdateAsync( filter, update, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The collection. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndUpdateAsync(this IMongoCollection collection, Expression> filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdateAsync( new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndUpdateAsync(this IMongoCollection collection, Expression> filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdateAsync(new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndUpdateAsync(this IMongoCollection collection, IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdateAsync( session, filter, update, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndUpdateAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdateAsync( session, new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Finds a single document and updates it atomically. /// /// The type of the document. /// The type of the projection (same as TDocument if there is no projection). /// The collection. /// The session. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The returned document. /// public static Task FindOneAndUpdateAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); return collection.FindOneAndUpdateAsync(session, new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Replaces a single document. /// /// The type of the document. /// The collection. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The result of the replacement. /// public static ReplaceOneResult ReplaceOne(this IMongoCollection collection, Expression> filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.ReplaceOne(new ExpressionFilterDefinition(filter), replacement, options, cancellationToken); } /// /// Replaces a single document. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The result of the replacement. /// public static ReplaceOneResult ReplaceOne(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.ReplaceOne(session, new ExpressionFilterDefinition(filter), replacement, options, cancellationToken); } /// /// Replaces a single document. /// /// The type of the document. /// The collection. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The result of the replacement. /// public static Task ReplaceOneAsync(this IMongoCollection collection, Expression> filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.ReplaceOneAsync(new ExpressionFilterDefinition(filter), replacement, options, cancellationToken); } /// /// Replaces a single document. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The replacement. /// The options. /// The cancellation token. /// /// The result of the replacement. /// public static Task ReplaceOneAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.ReplaceOneAsync(session, new ExpressionFilterDefinition(filter), replacement, options, cancellationToken); } /// /// Updates many documents. /// /// The type of the document. /// The collection. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The result of the update operation. /// public static UpdateResult UpdateMany(this IMongoCollection collection, Expression> filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.UpdateMany(new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Updates many documents. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The result of the update operation. /// public static UpdateResult UpdateMany(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.UpdateMany(session, new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Updates many documents. /// /// The type of the document. /// The collection. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The result of the update operation. /// public static Task UpdateManyAsync(this IMongoCollection collection, Expression> filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.UpdateManyAsync(new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Updates many documents. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The result of the update operation. /// public static Task UpdateManyAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.UpdateManyAsync(session, new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Updates a single document. /// /// The type of the document. /// The collection. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The result of the update operation. /// public static UpdateResult UpdateOne(this IMongoCollection collection, Expression> filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.UpdateOne( new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Updates a single document. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The result of the update operation. /// public static UpdateResult UpdateOne(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.UpdateOne( session, new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Updates a single document. /// /// The type of the document. /// The collection. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The result of the update operation. /// public static Task UpdateOneAsync(this IMongoCollection collection, Expression> filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(filter, nameof(filter)); return collection.UpdateOneAsync( new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Updates a single document. /// /// The type of the document. /// The collection. /// The session. /// The filter. /// The update. /// The options. /// The cancellation token. /// /// The result of the update operation. /// public static Task UpdateOneAsync(this IMongoCollection collection, IClientSessionHandle session, Expression> filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); Ensure.IsNotNull(filter, nameof(filter)); return collection.UpdateOneAsync( session, new ExpressionFilterDefinition(filter), update, options, cancellationToken); } /// /// Watches changes on the collection. /// /// The type of the document. /// The collection. /// The options. /// The cancellation token. /// /// A change stream. /// public static IAsyncCursor> Watch( this IMongoCollection collection, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); var emptyPipeline = new EmptyPipelineDefinition>(); return collection.Watch(emptyPipeline, options, cancellationToken); } /// /// Watches changes on the collection. /// /// The type of the document. /// The collection. /// The session. /// The options. /// The cancellation token. /// /// A change stream. /// public static IAsyncCursor> Watch( this IMongoCollection collection, IClientSessionHandle session, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); var emptyPipeline = new EmptyPipelineDefinition>(); return collection.Watch(session, emptyPipeline, options, cancellationToken); } /// /// Watches changes on the collection. /// /// The type of the document. /// The collection. /// The options. /// The cancellation token. /// /// A change stream. /// public static Task>> WatchAsync( this IMongoCollection collection, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); var emptyPipeline = new EmptyPipelineDefinition>(); return collection.WatchAsync(emptyPipeline, options, cancellationToken); } /// /// Watches changes on the collection. /// /// The type of the document. /// The collection. /// The session. /// The options. /// The cancellation token. /// /// A change stream. /// public static Task>> WatchAsync( this IMongoCollection collection, IClientSessionHandle session, ChangeStreamOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(collection, nameof(collection)); Ensure.IsNotNull(session, nameof(session)); var emptyPipeline = new EmptyPipelineDefinition>(); return collection.WatchAsync(session, emptyPipeline, options, cancellationToken); } } }