public class Aggregate extends Object
Instances of this class are constructed via the inner Aggregate.Builder
class.
Due to the potential complexity of pipelines and the associated operators the
Builder is intended to be used with the various support classes
including the Expressions
library. For example:
import static
com.allanbank.mongodb.builder.AggregationGroupField.set
; import staticcom.allanbank.mongodb.builder.AggregationGroupId.id
; import staticcom.allanbank.mongodb.builder.AggregationProjectFields.includeWithoutId
; import staticcom.allanbank.mongodb.builder.QueryBuilder.where
; import staticcom.allanbank.mongodb.builder.Sort.asc
; import staticcom.allanbank.mongodb.builder.Sort.desc
; import staticcom.allanbank.mongodb.builder.expression.Expressions.field
; import staticcom.allanbank.mongodb.builder.expression.Expressions.set
; DocumentBuilder b1 = BuilderFactory.start(); DocumentBuilder b2 = BuilderFactory.start(); Aggregate.Builder builder = new Aggregate.Builder(); builder.match(where("state").notEqualTo("NZ")) .group(id().addField("state") .addField("city"), set("pop").sum("pop")) .sort(asc("pop")) .group(id("_id.state"), set("biggestcity").last("_id.city"), set("biggestpop").last("pop"), set("smallestcity").first("_id.city"), set("smallestpop").first("pop")) .project( includeWithoutId(), set("state", field("_id")), set("biggestCity", b1.add(set("name", field("biggestcity"))).add( set("pop", field("biggestpop")))), set("smallestCity", b2.add(set("name", field("smallestcity"))).add( set("pop", field("smallestpop"))))) .sort(desc("biggestCity.pop"));
Modifier and Type | Class and Description |
---|---|
static class |
Aggregate.Builder
Builder provides the ability to construct aggregate command pipelines.
|
Modifier and Type | Field and Description |
---|---|
static Version |
ALLOW_DISK_USAGE_REQUIRED_VERSION
The first version of MongoDB to support the
$geoNear pipeline
operator. |
static Version |
CURSOR_VERSION
The first version of MongoDB to support the
aggregate command
using a cursor. |
static Version |
EXPLAIN_VERSION
The first version of MongoDB to support the
aggregate command
with the explain option. |
static Version |
GEO_NEAR_REQUIRED_VERSION
The first version of MongoDB to support the
$geoNear pipeline
operator. |
static Version |
MAX_TIMEOUT_VERSION
The first version of MongoDB to support the
aggregate command
with the ability to limit the execution time on the server. |
static Version |
REDACT_REQUIRED_VERSION
The first version of MongoDB to support the
$redact pipeline
operator. |
static Version |
REQUIRED_VERSION
The first version of MongoDB to support the
aggregate command. |
Modifier | Constructor and Description |
---|---|
protected |
Aggregate(Aggregate.Builder builder)
Creates a new Aggregation.
|
Modifier and Type | Method and Description |
---|---|
static Aggregate.Builder |
builder()
Creates a new builder for a
Aggregate . |
int |
getBatchSize()
Returns the number of documents to be returned in each batch of results
by the cursor.
|
int |
getCursorLimit()
Returns the total number of documents to be returned by the cursor.
|
long |
getMaximumTimeMilliseconds()
Returns the maximum amount of time to allow the command to run on the
Server before it is aborted.
|
List<Element> |
getPipeline()
Returns the pipeline of operations to apply.
|
ReadPreference |
getReadPreference()
Returns the
ReadPreference specifying which servers may be used
to execute the aggregation. |
Version |
getRequiredVersion()
Returns the version required for the aggregation.
|
boolean |
isAllowDiskUsage()
Returns true if the aggregation results should be allowed to spill to
disk.
|
boolean |
isUseCursor()
Returns true if the aggregation results should be returned as a cursor.
|
public static final Version ALLOW_DISK_USAGE_REQUIRED_VERSION
$geoNear
pipeline
operator.public static final Version CURSOR_VERSION
aggregate
command
using a cursor.public static final Version EXPLAIN_VERSION
aggregate
command
with the explain option.public static final Version GEO_NEAR_REQUIRED_VERSION
$geoNear
pipeline
operator.public static final Version MAX_TIMEOUT_VERSION
aggregate
command
with the ability to limit the execution time on the server.public static final Version REDACT_REQUIRED_VERSION
$redact
pipeline
operator.public static final Version REQUIRED_VERSION
aggregate
command.protected Aggregate(Aggregate.Builder builder)
builder
- The builder for the Aggregation instance.public static Aggregate.Builder builder()
Aggregate
.Aggregate
.public int getBatchSize()
public int getCursorLimit()
public long getMaximumTimeMilliseconds()
public List<Element> getPipeline()
public ReadPreference getReadPreference()
ReadPreference
specifying which servers may be used
to execute the aggregation.
If null
then the MongoCollection
instance's
ReadPreference
will be used.
MongoCollection.getReadPreference()
public Version getRequiredVersion()
public boolean isAllowDiskUsage()
public boolean isUseCursor()
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.