/// <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)); }
/// <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)); }
// 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"); }
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); } } }
// 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)); }
/// <inheritdoc /> public abstract Task <IAsyncCursor <TProjection> > FindAsync <TProjection>(FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
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)); }
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) }); }
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)); }
/// <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 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)); }
/// <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)); }
// 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"); }
/// <inheritdoc /> public virtual IAsyncCursor <TProjection> FindSync <TProjection>(FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); }
// 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)); }
/// <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(); }
public FindFluent <TDocument, TDocument> Find(object filter) { var options = new FindOptions <TDocument>(); return(new FindFluent <TDocument, TDocument>(this, filter, options)); }