Ejemplo n.º 1
0
 // constructors
 public FindFluent(IMongoCollection <TDocument> collection, FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options)
 {
     _collection = Ensure.IsNotNull(collection, "collection");
     _filter     = Ensure.IsNotNull(filter, "filter");
     _options    = Ensure.IsNotNull(options, "options");
 }
Ejemplo n.º 2
0
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateOneModel{TDocument}"/> class.
 /// </summary>
 /// <param name="filter">The filter.</param>
 /// <param name="update">The update.</param>
 public UpdateOneModel(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update)
 {
     _filter = Ensure.IsNotNull(filter, nameof(filter));
     _update = Ensure.IsNotNull(update, nameof(update));
 }
 /// <inheritdoc />
 public abstract IAggregateFluent <TResult> Match(FilterDefinition <TResult> filter);
Ejemplo n.º 4
0
 public override IAggregateFluent <TResult> Match(FilterDefinition <TResult> filter)
 {
     return(WithPipeline(_pipeline.Match(filter)));
 }
Ejemplo n.º 5
0
 // constructors
 public FindFluent(IMongoCollection <TDocument> collection, FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options)
 {
     _collection = Ensure.IsNotNull(collection, nameof(collection));
     _filter     = Ensure.IsNotNull(filter, nameof(filter));
     _options    = Ensure.IsNotNull(options, nameof(options));
 }
        /// <summary>
        /// Finds a single document and updates it atomically.
        /// </summary>
        /// <typeparam name="TDocument">The type of the document.</typeparam>
        /// <param name="collection">The collection.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="update">The update.</param>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The returned document.
        /// </returns>
        public static Task <TDocument> FindOneAndUpdateAsync <TDocument>(this IMongoCollection <TDocument> collection, FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(collection, "collection");
            Ensure.IsNotNull(collection, "filter");

            return(collection.FindOneAndUpdateAsync <TDocument>(
                       filter,
                       update,
                       options,
                       cancellationToken));
        }
        /// <summary>
        /// Finds the documents matching the filter.
        /// </summary>
        /// <typeparam name="TDocument">The type of the document.</typeparam>
        /// <param name="collection">The collection.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A Task whose result is a cursor.</returns>
        public static Task <IAsyncCursor <TDocument> > FindAsync <TDocument>(this IMongoCollection <TDocument> collection, FilterDefinition <TDocument> filter, FindOptions <TDocument, TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(collection, "collection");
            Ensure.IsNotNull(filter, "filter");

            return(collection.FindAsync <TDocument>(filter, options, cancellationToken));
        }
        /// <summary>
        /// Begins a fluent find interface.
        /// </summary>
        /// <typeparam name="TDocument">The type of the document.</typeparam>
        /// <param name="collection">The collection.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// A fluent find interface.
        /// </returns>
        public static IFindFluent <TDocument, TDocument> Find <TDocument>(this IMongoCollection <TDocument> collection, FilterDefinition <TDocument> filter, FindOptions options = null)
        {
            FindOptions <TDocument, TDocument> genericOptions;

            if (options == null)
            {
                genericOptions = new FindOptions <TDocument>();
            }
            else
            {
                genericOptions = new FindOptions <TDocument>
                {
                    AllowPartialResults = options.AllowPartialResults,
                    BatchSize           = options.BatchSize,
                    Comment             = options.Comment,
                    CursorType          = options.CursorType,
                    MaxTime             = options.MaxTime,
                    Modifiers           = options.Modifiers,
                    NoCursorTimeout     = options.NoCursorTimeout
                };
            }

            return(new FindFluent <TDocument, TDocument>(collection, filter, genericOptions));
        }
        /// <summary>
        /// Gets the distinct values for a specified field.
        /// </summary>
        /// <typeparam name="TDocument">The type of the document.</typeparam>
        /// <typeparam name="TField">The type of the result.</typeparam>
        /// <param name="collection">The collection.</param>
        /// <param name="field">The field.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The distinct values for the specified field.
        /// </returns>
        public static Task <IAsyncCursor <TField> > DistinctAsync <TDocument, TField>(this IMongoCollection <TDocument> collection, Expression <Func <TDocument, TField> > field, FilterDefinition <TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(collection, "collection");
            Ensure.IsNotNull(field, "field");
            Ensure.IsNotNull(filter, "filter");

            return(collection.DistinctAsync <TField>(
                       new ExpressionFieldDefinition <TDocument, TField>(field),
                       filter,
                       options,
                       cancellationToken));
        }