Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2012 David M. Carr 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.
 
 
 package org.bitbucket.davidm24.mongodb.aggregate;
 
Utility for creating DBObject aggregate commands.

Author(s):
David M. Carr
See also:
Aggregation Framework in MongoDB Manual
 
 public class AggregateBuilder {
     public AggregateBuilder(String collectionName) {
          = new BasicDBList();
          = new BasicDBObject();
         .put("aggregate"collectionName);
         .put("pipeline");
     }

    
Returns a new AggregateBuilder for the specified collection. All subsequent operators will be treated as part of the processing pipeline. When you're done adding to the pipeline, call get().

Parameters:
collection the collection within which to aggregate
Returns:
the new builder instance
 
     public static AggregateBuilder aggregate(DBCollection collection) {
         return aggregate(collection.getName());
     }

    
Returns a new AggregateBuilder for the specified collection. All subsequent operators will be treated as part of the processing pipeline. When you're done adding to the pipeline, call get().

Parameters:
collectionName the name of the collection within which to aggregate
Returns:
the new builder instance
 
     public static AggregateBuilder aggregate(String collectionName) {
         return new AggregateBuilder(collectionName);
     }
 
     private void addOperand(String opObject value) {
         .add(new BasicDBObject(opvalue));
     }
 
     public AggregateBuilder project(Object object) {
         addOperand(.object);
         return this;
     }
 
     public AggregateBuilder match(Object object) {
         addOperand(.object);
         return this;
     }

    
Shortcut for simple single-key, direct equality match clauses. For more complicated uses, use match(java.lang.Object).

Parameters:
key the field to match
value the precise value to match to
Returns:
the builder
 
     public AggregateBuilder match(String keyObject value) {
         return match(new BasicDBObject(keyvalue));
     }
 
     public AggregateBuilder limit(int count) {
         addOperand(.count);
         return this;
     }
 
     public AggregateBuilder skip(int count) {
         addOperand(.count);
         return this;
     }
 
     public AggregateBuilder unwind(String targetField) {
         addOperand(.targetField);
         return this;
     }
    public AggregateBuilder group(Object object) {
        addOperand(.object);
        return this;
    }

    
Shortcut for simple single-key group clauses. For more complicated uses, use group(java.lang.Object).

Parameters:
key the field to match
value the precise value to match to
Returns:
the builder
    public AggregateBuilder group(String keyObject value) {
        return group(new BasicDBObject(keyvalue));
    }
    public AggregateBuilder sort(Object object) {
        addOperand(.object);
        return this;
    }

    
Creates a DBObject to be passed to the driver's command operation

Returns:
Returns a DBObject instance
    public DBObject get() {
        return ;
    }
    private DBObject _command;
    private BasicDBList _pipeline;
New to GrepCode? Check out our FAQ X