Class AggregationPipelineImpl

    • Constructor Summary

      Constructors 
      Constructor Description
      AggregationPipelineImpl​(Datastore datastore, com.mongodb.DBCollection collection, java.lang.Class source)
      Creates an AggregationPipeline
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <U> java.util.Iterator<U> aggregate​(java.lang.Class<U> target)
      Executes the pipeline and aggregates the output in to the type mapped by the target type using the default options as defined in AggregationOptions.
      <U> java.util.Iterator<U> aggregate​(java.lang.Class<U> target, com.mongodb.AggregationOptions options)
      Executes the pipeline and aggregates the output in to the type mapped by the target type.
      <U> java.util.Iterator<U> aggregate​(java.lang.Class<U> target, com.mongodb.AggregationOptions options, com.mongodb.ReadPreference readPreference)
      Executes the pipeline and aggregates the output in to the type mapped by the target type.
      <U> java.util.Iterator<U> aggregate​(java.lang.String collectionName, java.lang.Class<U> target, com.mongodb.AggregationOptions options, com.mongodb.ReadPreference readPreference)
      Executes the pipeline and aggregates the output in to the type mapped by the target type.
      AggregationPipeline bucket​(java.lang.String field, java.util.List<?> boundaries)
      Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.
      AggregationPipeline bucket​(java.lang.String field, java.util.List<?> boundaries, BucketOptions options)
      Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.
      AggregationPipeline bucketAuto​(java.lang.String field, int bucketCount)
      Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression.
      AggregationPipeline bucketAuto​(java.lang.String field, int bucketCount, BucketAutoOptions options)
      Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression.
      AggregationPipeline geoNear​(GeoNear geoNear)
      Returns an ordered stream of documents based on the proximity to a geospatial point.
      java.util.List<com.mongodb.DBObject> getStages()  
      AggregationPipeline group​(Group... groupings)
      Groups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group .
      AggregationPipeline group​(java.lang.String id, Group... groupings)
      Groups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group.
      AggregationPipeline group​(java.util.List<Group> id, Group... groupings)  
      AggregationPipeline limit​(int count)
      Passes the first n documents unmodified to the pipeline where n is the specified limit.
      AggregationPipeline lookup​(java.lang.String from, java.lang.String localField, java.lang.String foreignField, java.lang.String as)
      Performs a left outer join to an unsharded collection in the same database to filter in documents from the "joined" collection for processing.
      AggregationPipeline match​(Query query)
      Filters the document stream to allow only matching documents to pass unmodified into the next pipeline stage.
      <U> java.util.Iterator<U> out​(java.lang.Class<U> target)
      Places the output of the aggregation in the collection mapped by the target type using the default options as defined in AggregationOptions.
      <U> java.util.Iterator<U> out​(java.lang.Class<U> target, com.mongodb.AggregationOptions options)
      Places the output of the aggregation in the collection mapped by the target type.
      <U> java.util.Iterator<U> out​(java.lang.String collectionName, java.lang.Class<U> target)
      Places the output of the aggregation in the collection mapped by the target type using the default options as defined in AggregationOptions.
      <U> java.util.Iterator<U> out​(java.lang.String collectionName, java.lang.Class<U> target, com.mongodb.AggregationOptions options)
      Places the output of the aggregation in the collection mapped by the target type.
      AggregationPipeline project​(Projection... projections)
      Reshapes each document in the stream, such as by adding new fields or removing existing fields.
      AggregationPipeline sample​(int sampleSize)
      Randomly selects the specified number of documents from the previous pipeline stage.
      AggregationPipeline skip​(int count)
      Skips the first n documents where n is the specified skip number and passes the remaining documents unmodified to the pipeline.
      AggregationPipeline sort​(Sort... sorts)
      Reorders the document stream by a specified sort key.
      AggregationPipeline sortByCount​(java.lang.String field)
      Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.
      java.lang.String toString()  
      AggregationPipeline unwind​(java.lang.String field)
      Deconstructs an array field from the input documents to output a document for each element.
      AggregationPipeline unwind​(java.lang.String field, com.mongodb.client.model.UnwindOptions options)
      Deconstructs an array field from the input documents to output a document for each element.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • AggregationPipelineImpl

        public AggregationPipelineImpl​(Datastore datastore,
                                       com.mongodb.DBCollection collection,
                                       java.lang.Class source)
        Creates an AggregationPipeline
        Parameters:
        datastore - the datastore to use
        collection - the database collection on which to operate
        source - the source type to aggregate
    • Method Detail

      • getStages

        public java.util.List<com.mongodb.DBObject> getStages()
        Returns:
        the stages
        Developer note. This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
      • aggregate

        public <U> java.util.Iterator<U> aggregate​(java.lang.Class<U> target)
        Description copied from interface: AggregationPipeline
        Executes the pipeline and aggregates the output in to the type mapped by the target type using the default options as defined in AggregationOptions. Note: This return type will change to MongoCursor in 2.0 to allow for finer-grained control of iteration and resource management.
        Specified by:
        aggregate in interface AggregationPipeline
        Type Parameters:
        U - type of the results
        Parameters:
        target - The class to use when iterating over the results
        Returns:
        an iterator of the computed results
      • aggregate

        public <U> java.util.Iterator<U> aggregate​(java.lang.Class<U> target,
                                                   com.mongodb.AggregationOptions options)
        Description copied from interface: AggregationPipeline
        Executes the pipeline and aggregates the output in to the type mapped by the target type. Note: This return type will change to MongoCursor in 2.0 to allow for finer-grained control of iteration and resource management.
        Specified by:
        aggregate in interface AggregationPipeline
        Type Parameters:
        U - type of the results
        Parameters:
        target - The class to use when iterating over the results
        options - The options to apply to this aggregation
        Returns:
        an iterator of the computed results
      • aggregate

        public <U> java.util.Iterator<U> aggregate​(java.lang.Class<U> target,
                                                   com.mongodb.AggregationOptions options,
                                                   com.mongodb.ReadPreference readPreference)
        Description copied from interface: AggregationPipeline
        Executes the pipeline and aggregates the output in to the type mapped by the target type. Note: This return type will change to MongoCursor in 2.0 to allow for finer-grained control of iteration and resource management.
        Specified by:
        aggregate in interface AggregationPipeline
        Type Parameters:
        U - type of the results
        Parameters:
        target - The class to use when iterating over the results
        options - The options to apply to this aggregation
        readPreference - The read preference to apply to this pipeline
        Returns:
        an iterator of the computed results
      • aggregate

        public <U> java.util.Iterator<U> aggregate​(java.lang.String collectionName,
                                                   java.lang.Class<U> target,
                                                   com.mongodb.AggregationOptions options,
                                                   com.mongodb.ReadPreference readPreference)
        Description copied from interface: AggregationPipeline
        Executes the pipeline and aggregates the output in to the type mapped by the target type. Note: This return type will change to MongoCursor in 2.0 to allow for finer-grained control of iteration and resource management.
        Specified by:
        aggregate in interface AggregationPipeline
        Type Parameters:
        U - type of the results
        Parameters:
        collectionName - The collection in which to store the results of the aggregation overriding the mapped value in target
        target - The class to use when iterating over the results
        options - The options to apply to this aggregation
        readPreference - The read preference to apply to this pipeline
        Returns:
        an iterator of the computed results
      • geoNear

        public AggregationPipeline geoNear​(GeoNear geoNear)
        Description copied from interface: AggregationPipeline
        Returns an ordered stream of documents based on the proximity to a geospatial point. Incorporates the functionality of $match, $sort, and $limit for geospatial data. The output documents include an additional distance field and can include a location identifier field.
        Specified by:
        geoNear in interface AggregationPipeline
        Parameters:
        geoNear - the geospatial parameters to apply to the pipeline
        Returns:
        this
      • group

        public AggregationPipeline group​(Group... groupings)
        Description copied from interface: AggregationPipeline
        Groups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group . Consumes all input documents and outputs one document per each distinct group. The output documents only contain the identifier field and, if specified, accumulated fields. The ID for this group is null.
        Specified by:
        group in interface AggregationPipeline
        Parameters:
        groupings - the group definitions
        Returns:
        this
      • group

        public AggregationPipeline group​(java.lang.String id,
                                         Group... groupings)
        Description copied from interface: AggregationPipeline
        Groups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group. Consumes all input documents and outputs one document per each distinct group. The output documents only contain the identifier field and, if specified, accumulated fields.
        Specified by:
        group in interface AggregationPipeline
        Parameters:
        id - the ID of the group create
        groupings - the group definitions
        Returns:
        this
      • limit

        public AggregationPipeline limit​(int count)
        Description copied from interface: AggregationPipeline
        Passes the first n documents unmodified to the pipeline where n is the specified limit. For each input document, outputs either one document (for the first n documents) or zero documents (after the first n documents).
        Specified by:
        limit in interface AggregationPipeline
        Parameters:
        count - the maximum number of documents to return
        Returns:
        this
      • lookup

        public AggregationPipeline lookup​(java.lang.String from,
                                          java.lang.String localField,
                                          java.lang.String foreignField,
                                          java.lang.String as)
        Description copied from interface: AggregationPipeline
        Performs a left outer join to an unsharded collection in the same database to filter in documents from the "joined" collection for processing. The $lookup stage does an equality match between a field from the input documents with a field from the documents of the “joined” collection. To each input document, the $lookup stage adds a new array field whose elements are the matching documents from the “joined” collection. The $lookup stage passes these reshaped documents to the next stage.
        Specified by:
        lookup in interface AggregationPipeline
        Parameters:
        from - the collection to join
        localField - the field from the input documents
        foreignField - the field from the documents of the "from" collection
        as - the output array field
        Returns:
        this
      • match

        public AggregationPipeline match​(Query query)
        Description copied from interface: AggregationPipeline
        Filters the document stream to allow only matching documents to pass unmodified into the next pipeline stage. $match uses standard MongoDB queries. For each input document, outputs either one document (a match) or zero documents (no match).
        Specified by:
        match in interface AggregationPipeline
        Parameters:
        query - the query to use when matching
        Returns:
        this
      • sample

        public AggregationPipeline sample​(int sampleSize)
        Description copied from interface: AggregationPipeline
        Randomly selects the specified number of documents from the previous pipeline stage.
        Specified by:
        sample in interface AggregationPipeline
        Parameters:
        sampleSize - the number of documents to select
        Returns:
        this
      • out

        public <U> java.util.Iterator<U> out​(java.lang.Class<U> target)
        Description copied from interface: AggregationPipeline
        Places the output of the aggregation in the collection mapped by the target type using the default options as defined in AggregationOptions.
        Specified by:
        out in interface AggregationPipeline
        Type Parameters:
        U - type of the results
        Parameters:
        target - The class to use when iterating over the results
        Returns:
        an iterator of the computed results
      • out

        public <U> java.util.Iterator<U> out​(java.lang.Class<U> target,
                                             com.mongodb.AggregationOptions options)
        Description copied from interface: AggregationPipeline
        Places the output of the aggregation in the collection mapped by the target type.
        Specified by:
        out in interface AggregationPipeline
        Type Parameters:
        U - type of the results
        Parameters:
        target - The class to use when iterating over the results
        options - The options to apply to this aggregation
        Returns:
        an iterator of the computed results
      • out

        public <U> java.util.Iterator<U> out​(java.lang.String collectionName,
                                             java.lang.Class<U> target)
        Description copied from interface: AggregationPipeline
        Places the output of the aggregation in the collection mapped by the target type using the default options as defined in AggregationOptions.
        Specified by:
        out in interface AggregationPipeline
        Type Parameters:
        U - type of the results
        Parameters:
        collectionName - The collection in which to store the results of the aggregation overriding the mapped value in target
        target - The class to use when iterating over the results
        Returns:
        an iterator of the computed results
      • out

        public <U> java.util.Iterator<U> out​(java.lang.String collectionName,
                                             java.lang.Class<U> target,
                                             com.mongodb.AggregationOptions options)
        Description copied from interface: AggregationPipeline
        Places the output of the aggregation in the collection mapped by the target type.
        Specified by:
        out in interface AggregationPipeline
        Type Parameters:
        U - type of the results
        Parameters:
        collectionName - The collection in which to store the results of the aggregation overriding the mapped value in target
        target - The class to use when iterating over the results
        options - The options to apply to this aggregation
        Returns:
        an iterator of the computed results
      • project

        public AggregationPipeline project​(Projection... projections)
        Description copied from interface: AggregationPipeline
        Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document.
        Specified by:
        project in interface AggregationPipeline
        Parameters:
        projections - the projections to apply to this pipeline
        Returns:
        this
      • skip

        public AggregationPipeline skip​(int count)
        Description copied from interface: AggregationPipeline
        Skips the first n documents where n is the specified skip number and passes the remaining documents unmodified to the pipeline. For each input document, outputs either zero documents (for the first n documents) or one document (if after the first n documents).
        Specified by:
        skip in interface AggregationPipeline
        Parameters:
        count - the number of documents to skip
        Returns:
        this
      • sort

        public AggregationPipeline sort​(Sort... sorts)
        Description copied from interface: AggregationPipeline
        Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document.
        Specified by:
        sort in interface AggregationPipeline
        Parameters:
        sorts - the sorts to apply to this pipeline
        Returns:
        this
      • unwind

        public AggregationPipeline unwind​(java.lang.String field)
        Description copied from interface: AggregationPipeline
        Deconstructs an array field from the input documents to output a document for each element. Each output document replaces the array with an element value. For each input document, outputs n documents where n is the number of array elements and can be zero for an empty array.
        Specified by:
        unwind in interface AggregationPipeline
        Parameters:
        field - the field to unwind
        Returns:
        this
      • unwind

        public AggregationPipeline unwind​(java.lang.String field,
                                          com.mongodb.client.model.UnwindOptions options)
        Description copied from interface: AggregationPipeline
        Deconstructs an array field from the input documents to output a document for each element. Each output document replaces the array with an element value. For each input document, outputs n documents where n is the number of array elements and can be zero for an empty array.
        Specified by:
        unwind in interface AggregationPipeline
        Parameters:
        field - the field to unwind
        options - unwind options
        Returns:
        this
      • sortByCount

        public AggregationPipeline sortByCount​(java.lang.String field)
        Description copied from interface: AggregationPipeline
        Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.

        Each output document contains two fields: an _id field containing the distinct grouping value, and a count field containing the number of documents belonging to that grouping or category.

        Specified by:
        sortByCount in interface AggregationPipeline
        Parameters:
        field - the field to sort by count
        Returns:
        this
      • bucket

        public AggregationPipeline bucket​(java.lang.String field,
                                          java.util.List<?> boundaries)
        Description copied from interface: AggregationPipeline
        Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.

        Each bucket is represented as a document in the output. The document for each bucket contains an _id field, whose value specifies the inclusive lower bound of the bucket and a count field that contains the number of documents in the bucket. The count field is included by default when the output is not specified.

        Specified by:
        bucket in interface AggregationPipeline
        Parameters:
        field - the field that used as groupby for bucketing
        boundaries - An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries.
        Returns:
        this
      • bucket

        public AggregationPipeline bucket​(java.lang.String field,
                                          java.util.List<?> boundaries,
                                          BucketOptions options)
        Description copied from interface: AggregationPipeline
        Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.

        Each bucket is represented as a document in the output. The document for each bucket contains an _id field, whose value specifies the inclusive lower bound of the bucket and a count field that contains the number of documents in the bucket. The count field is included by default when the output is not specified.

        Specified by:
        bucket in interface AggregationPipeline
        Parameters:
        field - the field that used as groupby for bucketing
        boundaries - An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries.
        options - options that include defaultField for values that not match in any boundaries and also allow to specify output by using accumulator Accumulator
        Returns:
        this
      • bucketAuto

        public AggregationPipeline bucketAuto​(java.lang.String field,
                                              int bucketCount)
        Description copied from interface: AggregationPipeline
        Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically determined in an attempt to evenly distribute the documents into the specified number of buckets.

        Each bucket is represented as a document in the output. The document for each bucket contains an _id field, whose value specifies the inclusive lower bound and the exclusive upper bound for the bucket, and a count field that contains the number of documents in the bucket. The count field is included by default when the output is not specified.

        Specified by:
        bucketAuto in interface AggregationPipeline
        Parameters:
        field - the field that used as groupby for auto bucketing
        bucketCount - the number of buckets into which input documents are grouped
        Returns:
        this
      • bucketAuto

        public AggregationPipeline bucketAuto​(java.lang.String field,
                                              int bucketCount,
                                              BucketAutoOptions options)
        Description copied from interface: AggregationPipeline
        Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically determined in an attempt to evenly distribute the documents into the specified number of buckets.

        Each bucket is represented as a document in the output. The document for each bucket contains an _id field, whose value specifies the inclusive lower bound and the exclusive upper bound for the bucket, and a count field that contains the number of documents in the bucket. The count field is included by default when the output is not specified.

        Specified by:
        bucketAuto in interface AggregationPipeline
        Parameters:
        field - the field that used as groupby for auto bucketing
        bucketCount - the number of buckets into which input documents are grouped
        options - options that include granularity for buckets and output
        Returns:
        this
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object