/* 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.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
namespace MongoDB.Driver
{
///
/// Fluent interface for aggregate.
///
///
/// This interface is not guaranteed to remain stable. Implementors should use
/// .
///
/// The type of the result of the pipeline.
public interface IAggregateFluent : IAsyncCursorSource
{
///
/// Gets the database.
///
IMongoDatabase Database { get; }
///
/// Gets the options.
///
AggregateOptions Options { get; }
///
/// Gets the stages.
///
IList Stages { get; }
///
/// Appends the stage to the pipeline.
///
/// The type of the result of the stage.
/// The stage.
/// The fluent aggregate interface.
IAggregateFluent AppendStage(PipelineStageDefinition stage);
///
/// Changes the result type of the pipeline.
///
/// The type of the new result.
/// The new result serializer.
/// The fluent aggregate interface.
IAggregateFluent As(IBsonSerializer newResultSerializer = null);
///
/// Appends a $bucket stage to the pipeline.
///
/// The type of the value.
/// The expression providing the value to group by.
/// The bucket boundaries.
/// The options.
/// The fluent aggregate interface.
IAggregateFluent> Bucket(
AggregateExpressionDefinition groupBy,
IEnumerable boundaries,
AggregateBucketOptions options = null);
///
/// Appends a $bucket stage to the pipeline with a custom projection.
///
/// The type of the value.
/// The type of the new result.
/// The expression providing the value to group by.
/// The bucket boundaries.
/// The output projection.
/// The options.
/// The fluent aggregate interface.
IAggregateFluent Bucket(
AggregateExpressionDefinition groupBy,
IEnumerable boundaries,
ProjectionDefinition output,
AggregateBucketOptions options = null);
///
/// Appends a $bucketAuto stage to the pipeline.
///
/// The type of the value.
/// The expression providing the value to group by.
/// The number of buckets.
/// The options (optional).
/// The fluent aggregate interface.
IAggregateFluent> BucketAuto(
AggregateExpressionDefinition groupBy,
int buckets,
AggregateBucketAutoOptions options = null);
///
/// Appends a $bucketAuto stage to the pipeline with a custom projection.
///
/// The type of the value.
/// The type of the new result.
/// The expression providing the value to group by.
/// The number of buckets.
/// The output projection.
/// The options (optional).
/// The fluent aggregate interface.
IAggregateFluent BucketAuto(
AggregateExpressionDefinition groupBy,
int buckets,
ProjectionDefinition output,
AggregateBucketAutoOptions options = null);
///
/// Appends a $changeStream stage to the pipeline.
/// Normally you would prefer to use the Watch method of .
/// Only use this method if subsequent stages project away the resume token (the _id)
/// or you don't want the resulting cursor to automatically resume.
///
/// The options.
/// The fluent aggregate interface.
IAggregateFluent> ChangeStream(ChangeStreamStageOptions options = null);
///
/// Appends a count stage to the pipeline.
///
/// The fluent aggregate interface.
IAggregateFluent Count();
///
/// Appends a $facet stage to the pipeline.
///
/// The type of the new result.
/// The facets.
/// The options.
///
/// The fluent aggregate interface.
///
IAggregateFluent Facet(
IEnumerable> facets,
AggregateFacetOptions options = null);
///
/// Appends a $graphLookup stage to the pipeline.
///
/// The type of the from documents.
/// The type of the connect from field (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).
/// The type of the connect to field.
/// The type of the start with expression (must be either TConnectTo or a type that implements IEnumerable{TConnectTo}).
/// The type of the as field elements.
/// The type of the as field.
/// The type of the new result (must be same as TResult with an additional as field).
/// The from collection.
/// The connect from field.
/// The connect to field.
/// The start with value.
/// The as field.
/// The depth field.
/// The options.
/// The fluent aggregate interface.
IAggregateFluent GraphLookup(
IMongoCollection from,
FieldDefinition connectFromField,
FieldDefinition connectToField,
AggregateExpressionDefinition startWith,
FieldDefinition @as,
FieldDefinition depthField,
AggregateGraphLookupOptions options = null)
where TAs : IEnumerable;
///
/// Appends a group stage to the pipeline.
///
/// The type of the result of the stage.
/// The group projection.
/// The fluent aggregate interface.
IAggregateFluent Group(ProjectionDefinition group);
///
/// Appends a limit stage to the pipeline.
///
/// The limit.
/// The fluent aggregate interface.
IAggregateFluent Limit(int limit);
///
/// Appends a lookup stage to the pipeline.
///
/// The type of the foreign document.
/// The type of the new result.
/// Name of the other collection.
/// The local field.
/// The foreign field.
/// The field in to place the foreign results.
/// The options.
/// The fluent aggregate interface.
IAggregateFluent Lookup(string foreignCollectionName, FieldDefinition localField, FieldDefinition foreignField, FieldDefinition @as, AggregateLookupOptions options = null);
///
/// Appends a lookup stage to the pipeline.
///
/// The type of the foreign collection documents.
/// The type of the as field elements.
/// The type of the as field.
/// The type of the new result.
/// The foreign collection.
/// The "let" definition.
/// The lookup pipeline.
/// The as field in in which to place the results of the lookup pipeline.
/// The options.
/// The fluent aggregate interface.
IAggregateFluent Lookup(
IMongoCollection foreignCollection,
BsonDocument let,
PipelineDefinition lookupPipeline,
FieldDefinition @as,
AggregateLookupOptions options = null)
where TAs : IEnumerable;
///
/// Appends a match stage to the pipeline.
///
/// The filter.
/// The fluent aggregate interface.
IAggregateFluent Match(FilterDefinition filter);
///
/// Appends a match stage to the pipeline that matches derived documents and changes the result type to the derived type.
///
/// The type of the derived documents.
/// The new result serializer.
/// The fluent aggregate interface.
IAggregateFluent OfType(IBsonSerializer newResultSerializer = null) where TNewResult : TResult;
///
/// Appends an out stage to the pipeline and executes it, and then returns a cursor to read the contents of the output collection.
///
/// Name of the collection.
/// The cancellation token.
/// A cursor.
IAsyncCursor Out(string collectionName, CancellationToken cancellationToken = default(CancellationToken));
///
/// Appends an out stage to the pipeline and executes it, and then returns a cursor to read the contents of the output collection.
///
/// Name of the collection.
/// The cancellation token.
/// A Task whose result is a cursor.
Task> OutAsync(string collectionName, CancellationToken cancellationToken = default(CancellationToken));
///
/// Appends a project stage to the pipeline.
///
/// The type of the result of the stage.
/// The projection.
///
/// The fluent aggregate interface.
///
IAggregateFluent Project(ProjectionDefinition projection);
///
/// Appends a $replaceRoot stage to the pipeline.
///
/// The type of the new result.
/// The new root.
/// The fluent aggregate interface.
IAggregateFluent ReplaceRoot(AggregateExpressionDefinition newRoot);
///
/// Appends a skip stage to the pipeline.
///
/// The number of documents to skip.
/// The fluent aggregate interface.
IAggregateFluent Skip(int skip);
///
/// Appends a sort stage to the pipeline.
///
/// The sort specification.
/// The fluent aggregate interface.
IAggregateFluent Sort(SortDefinition sort);
///
/// Appends a sortByCount stage to the pipeline.
///
/// The type of the identifier.
/// The identifier.
/// The fluent aggregate interface.
IAggregateFluent> SortByCount(AggregateExpressionDefinition id);
///
/// Appends an unwind stage to the pipeline.
///
/// The type of the result of the stage.
/// The field.
/// The new result serializer.
///
/// The fluent aggregate interface.
///
[Obsolete("Use the Unwind overload which takes an options parameter.")]
IAggregateFluent Unwind(FieldDefinition field, IBsonSerializer newResultSerializer);
///
/// Appends an unwind stage to the pipeline.
///
/// The type of the new result.
/// The field.
/// The options.
/// The fluent aggregate interface.
IAggregateFluent Unwind(FieldDefinition field, AggregateUnwindOptions options = null);
}
///
/// Fluent interface for aggregate.
///
/// The type of the result.
public interface IOrderedAggregateFluent : IAggregateFluent
{
///
/// Combines the current sort definition with an additional sort definition.
///
/// The new sort.
/// The fluent aggregate interface.
IOrderedAggregateFluent ThenBy(SortDefinition newSort);
}
}