Aggregate

trait Aggregate
Companion
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def bucketAuto[TExpression](groupBy: TExpression, buckets: Int, options: BucketAutoOptions): Aggregate

Creates a $bucketAuto pipeline stage

Creates a $bucketAuto pipeline stage

Value Params
buckets

the number of the buckets

groupBy

the criteria to group By

options

the optional values for the $bucketAuto stage

Returns

the $bucketAuto pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/

Since

3.4

def combinedWith(anotherAggregate: Aggregate): Aggregate

Merges 2 aggregation pipelines together.

Merges 2 aggregation pipelines together.

Value Params
anotherAggregate

the aggregate to be merged with

Returns

the aggregate pipeline

Creates a $count pipeline stage using the field name "count" to store the result

Creates a $count pipeline stage using the field name "count" to store the result

Returns

the $count pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/count/

Since

3.4

def count(field: String): Aggregate

Creates a $count pipeline stage using the named field to store the result

Creates a $count pipeline stage using the named field to store the result

Value Params
field

the field in which to store the count

Returns

the $count pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/count/

Since

3.4

def graphLookup[TExpression](from: String, startWith: TExpression, connectFromField: String, connectToField: String, as: String, options: GraphLookupOptions): Aggregate

Creates a graphLookup pipeline stage for the specified filter

Creates a graphLookup pipeline stage for the specified filter

Value Params
as

name of field in output document

connectFromField

the from field

connectToField

the to field

from

the collection to query

options

optional values for the graphLookup

startWith

the expression to start the graph lookup with

Returns

the $graphLookup pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/

Since

3.4

def group[TExpression](id: TExpression, fieldAccumulators: Accumulator): Aggregate

Creates a $group pipeline stage for the specified filter

Creates a $group pipeline stage for the specified filter

Value Params
fieldAccumulators

zero or more field accumulator pairs

id

the id expression for the group

Returns

the $group pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/group/

def limit(n: Int): Aggregate

Creates a $limit pipeline stage for the specified filter

Creates a $limit pipeline stage for the specified filter

Value Params
n

the limit

Returns

the $limit pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/limi/

def lookup(from: String, localField: String, foreignField: String, as: String): Aggregate

Creates a $lookup pipeline stage, joining the current collection with the one specified in from using equality match between the local field and the foreign field

Creates a $lookup pipeline stage, joining the current collection with the one specified in from using equality match between the local field and the foreign field

Value Params
as

the name of the new array field to add to the input documents.

foreignField

the field in the from collection to match values against.

from

the name of the collection in the same database to perform the join with.

localField

the field from the local collection to match values against.

Returns

the $lookup pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/

Since

3.2

def lookup(from: String, pipeline: Aggregate, as: String): Aggregate

Creates a $lookup pipeline stage, joining the current collection with the one specified in from using the given pipeline

Creates a $lookup pipeline stage, joining the current collection with the one specified in from using the given pipeline

Value Params
as

the name of the new array field to add to the input documents.

from

the name of the collection in the same database to perform the join with.

pipeline

the pipeline to run on the joined collection.

Returns

the $lookup pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/

Since

3.7

def matchBy(filter: Filter): Aggregate

Creates a $match pipeline stage for the specified filter

Creates a $match pipeline stage for the specified filter

Value Params
filter

the filter to match

Returns

the $match pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/match/

def merge(collectionName: String, options: MergeOptions): Aggregate

Creates a $merge pipeline stage that merges into the specified collection using the specified options.

Creates a $merge pipeline stage that merges into the specified collection using the specified options.

Value Params
collectionName

the name of the collection to merge into

options

the merge options

Returns

the $merge pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/merge/

Since

3.11

def out(collectionName: String): Aggregate

Creates a $out pipeline stage that writes into the specified collection

Creates a $out pipeline stage that writes into the specified collection

Value Params
collectionName

the collection name

Returns

the $out pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/out/

def out(databaseName: String, collectionName: String): Aggregate

Creates a $out pipeline stage that supports outputting to a different database.

Creates a $out pipeline stage that supports outputting to a different database.

Value Params
collectionName

the collection name

databaseName

the database name

Returns

the $out pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/out/

Since

4.1

def project(projection: Projection): Aggregate

Creates a $project pipeline stage for the specified projection

Creates a $project pipeline stage for the specified projection

Value Params
projection

the projection

Returns

the $project pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/project/

def replaceWith[TExpression](value: TExpression): Aggregate

Creates a $replaceRoot pipeline stage

Creates a $replaceRoot pipeline stage

With $replaceWith, you can promote an embedded document to the top-level. You can also specify a new document as the replacement.

Value Params
value

the new root value

Returns

the $replaceRoot pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/replaceWith/

Since

3.11

def sample(size: Int): Aggregate

Creates a $sample pipeline stage with the specified sample size

Creates a $sample pipeline stage with the specified sample size

Value Params
size

the sample size

Returns

the $sample pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/sample/

Since

3.2

def skip(n: Int): Aggregate

Creates a $skip pipeline stage

Creates a $skip pipeline stage

Value Params
n

the number of documents to skip

Returns

the $skip pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/skip/

def sort(sort: Sort): Aggregate

Creates a $sort pipeline stage for the specified sort specification

Creates a $sort pipeline stage for the specified sort specification

Value Params
sort

the sort specification

Returns

the $sort pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/sort/

def sortByCount[TExpression](filter: TExpression): Aggregate

Creates a $sortByCount pipeline stage for the specified filter

Creates a $sortByCount pipeline stage for the specified filter

Value Params
filter

the filter specification

Returns

the $sortByCount pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/sortByCount/

Since

3.4

def unionWith(collection: String, pipeline: Aggregate): Aggregate

Creates a $unionWith pipeline stage.

Creates a $unionWith pipeline stage.

Value Params
collection

the name of the collection in the same database to perform the union with.

pipeline

the pipeline to run on the union.

Returns

the $unionWith pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/unionWith/

Since

4.1

def unwind(fieldName: String, unwindOptions: UnwindOptions): Aggregate

Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a '$' sign.

Creates a $unwind pipeline stage for the specified field name, which must be prefixed by a '$' sign.

Value Params
fieldName

the field name, prefixed by a '$' sign

unwindOptions

options for the unwind pipeline stage

Returns

the $unwind pipeline stage https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/

Since

3.2