예제 #1
0
        /// <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,
                    OplogReplay         = options.OplogReplay
                };
            }

            return(new FindFluent <TDocument, TDocument>(collection, filter, genericOptions));
        }
예제 #2
0
        /// <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 interface.
        /// </returns>
        public static IFindFluent <TDocument, TDocument> Find <TDocument>(this IMongoCollection <TDocument> collection, Expression <Func <TDocument, bool> > filter, FindOptions options = null)
        {
            Ensure.IsNotNull(collection, nameof(collection));
            Ensure.IsNotNull(filter, nameof(filter));

            return(collection.Find(new ExpressionFilterDefinition <TDocument>(filter), options));
        }
 public override IAsyncCursor <TProjection> FindSync <TProjection>(IClientSessionHandle session, FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_wrappedCollection.FindSync(session, CombineFilters(filter), options, cancellationToken));
 }
 public override Task <IAsyncCursor <TProjection> > FindAsync <TProjection>(FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_wrappedCollection.FindAsync(CombineFilters(filter), options, cancellationToken));
 }
예제 #5
0
 // constructors
 public FindFluent(IMongoCollection <TDocument> collection, object filter, FindOptions <TResult> options)
 {
     _collection = Ensure.IsNotNull(collection, "collection");
     _filter     = Ensure.IsNotNull(filter, "filter");
     _options    = Ensure.IsNotNull(options, "options");
 }
예제 #6
0
        public static async IAsyncEnumerable <TDocument> ToAsyncEnumerable <TDocument>(this IMongoCollection <TDocument> collection, FilterDefinition <TDocument> filter, FindOptions <TDocument, TDocument> options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            using var cursor = await collection.FindAsync(filter, options, cancellationToken);

            while (await cursor.MoveNextAsync())
            {
                foreach (var doc in cursor.Current)
                {
                    yield return(doc);
                }
            }
        }
예제 #7
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));
 }
예제 #8
0
 /// <inheritdoc />
 public abstract Task <IAsyncCursor <TProjection> > FindAsync <TProjection>(FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
예제 #9
0
        public override Task <IAsyncCursor <TProjection> > FindAsync <TProjection>(FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(filter, nameof(filter));
            options = options ?? new FindOptions <TDocument, TProjection>();

            var operation = CreateFindOperation <TProjection>(filter, options);

            return(ExecuteReadOperationAsync(operation, cancellationToken));
        }
예제 #10
0
        private FindOperation <TProjection> CreateFindOperation <TProjection>(FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options)
        {
            var projection         = options.Projection ?? new ClientSideDeserializationProjectionDefinition <TDocument, TProjection>();
            var renderedProjection = projection.Render(_documentSerializer, _settings.SerializerRegistry);

            return(new FindOperation <TProjection>(
                       _collectionNamespace,
                       renderedProjection.ProjectionSerializer,
                       _messageEncoderSettings)
            {
                AllowPartialResults = options.AllowPartialResults,
                BatchSize = options.BatchSize,
                Comment = options.Comment,
                CursorType = options.CursorType.ToCore(),
                Filter = filter.Render(_documentSerializer, _settings.SerializerRegistry),
                Limit = options.Limit,
                MaxAwaitTime = options.MaxAwaitTime,
                MaxTime = options.MaxTime,
                Modifiers = options.Modifiers,
                NoCursorTimeout = options.NoCursorTimeout,
                OplogReplay = options.OplogReplay,
                Projection = renderedProjection.Document,
                ReadConcern = _settings.ReadConcern,
                Skip = options.Skip,
                Sort = options.Sort == null ? null : options.Sort.Render(_documentSerializer, _settings.SerializerRegistry)
            });
        }
예제 #11
0
        public override Task <IAsyncCursor <TProjection> > FindAsync <TProjection>(FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(filter, nameof(filter));

            options = options ?? new FindOptions <TDocument, TProjection>();
            var projection         = options.Projection ?? new ClientSideDeserializationProjectionDefinition <TDocument, TProjection>();
            var renderedProjection = projection.Render(_documentSerializer, _settings.SerializerRegistry);

            var operation = new FindOperation <TProjection>(
                _collectionNamespace,
                renderedProjection.ProjectionSerializer,
                _messageEncoderSettings)
            {
                AllowPartialResults = options.AllowPartialResults,
                BatchSize           = options.BatchSize,
                Comment             = options.Comment,
                CursorType          = options.CursorType.ToCore(),
                Filter          = filter.Render(_documentSerializer, _settings.SerializerRegistry),
                Limit           = options.Limit,
                MaxTime         = options.MaxTime,
                Modifiers       = options.Modifiers,
                NoCursorTimeout = options.NoCursorTimeout,
                OplogReplay     = options.OplogReplay,
                Projection      = renderedProjection.Document,
                ReadConcern     = _settings.ReadConcern,
                Skip            = options.Skip,
                Sort            = options.Sort == null ? null : options.Sort.Render(_documentSerializer, _settings.SerializerRegistry)
            };

            return(ExecuteReadOperationAsync(operation, cancellationToken));
        }
예제 #12
0
        /// <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));
        }
예제 #13
0
        /// <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 interface.
        /// </returns>
        public static IFindFluent <TDocument, TDocument> Find <TDocument>(this IMongoCollection <TDocument> collection, Expression <Func <TDocument, bool> > filter, FindOptions options = null)
        {
            Ensure.IsNotNull(collection, "collection");
            Ensure.IsNotNull(filter, "filter");

            return(Find(collection, (object)filter, options));
        }
예제 #14
0
        /// <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, Expression <Func <TDocument, bool> > filter, FindOptions <TDocument, TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(collection, nameof(collection));
            Ensure.IsNotNull(filter, nameof(filter));

            return(collection.FindAsync <TDocument>(new ExpressionFilterDefinition <TDocument>(filter), options, cancellationToken));
        }
예제 #15
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");
 }
예제 #16
0
 /// <inheritdoc />
 public virtual IAsyncCursor <TProjection> FindSync <TProjection>(FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
예제 #17
0
 // constructors
 public FindFluent(IClientSessionHandle session, IMongoCollection <TDocument> collection, FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options)
 {
     _session    = session; // can be null
     _collection = Ensure.IsNotNull(collection, nameof(collection));
     _filter     = Ensure.IsNotNull(filter, nameof(filter));
     _options    = Ensure.IsNotNull(options, nameof(options));
 }
예제 #18
0
 /// <inheritdoc />
 public virtual Task <IAsyncCursor <TProjection> > FindAsync <TProjection>(IClientSessionHandle session, FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
예제 #19
0
        public FindFluent <TDocument, TDocument> Find(object filter)
        {
            var options = new FindOptions <TDocument>();

            return(new FindFluent <TDocument, TDocument>(this, filter, options));
        }