com.mongodb.AggregationOptions Java Examples
The following examples show how to use
com.mongodb.AggregationOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AggregationTest.java From bugu-mongo with Apache License 2.0 | 7 votes |
/** * Do aggregation with options. */ //@Test public void testWithOptions(){ connectDB(); BookDao dao = new BookDao(); Iterable<DBObject> it = dao.aggregate() .setOptions(AggregationOptions.builder().allowDiskUse(Boolean.TRUE).build()) .sort("{price : -1}") .results(); for(DBObject dbo : it){ System.out.println(dbo.get("price")); } disconnectDB(); }
Example #2
Source File: BuguAggregation.java From bugu-mongo with Apache License 2.0 | 6 votes |
@Override public Iterable<DBObject> results(){ if(options == null){ options = AggregationOptions.builder().build(); } final Iterator<DBObject> it = coll.aggregate(pipeline, options); return new Iterable<DBObject>() { @Override public Iterator<DBObject> iterator() { return it; } }; }
Example #3
Source File: MongodbInputDiscoverFieldsImplTest.java From pentaho-mongodb-plugin with Apache License 2.0 | 6 votes |
@Test public void testPipelineQueryIsLimited() throws KettleException, MongoDbException { setupPerform(); String query = "{$sort : 1}"; // Setup DBObjects collection List<DBObject> dbObjects = new ArrayList<DBObject>(); DBObject firstOp = (DBObject) JSON.parse( query ); DBObject[] remainder = { new BasicDBObject( "$limit", NUM_DOCS_TO_SAMPLE ) }; dbObjects.add( firstOp ); Collections.addAll( dbObjects, remainder ); AggregationOptions options = AggregationOptions.builder().build(); //when( MongodbInputDiscoverFieldsImpl.jsonPipelineToDBObjectList( query ) ).thenReturn( dbObjects ); when( collection.aggregate( anyList(), any( AggregationOptions.class ) ) ) .thenReturn( cursor ); discoverFields.discoverFields( new MongoProperties.Builder(), "mydb", "mycollection", query, "", true, NUM_DOCS_TO_SAMPLE, inputMeta ); verify( collection ).aggregate( anyList(), any( AggregationOptions.class ) ); }
Example #4
Source File: AggregationPipelineImpl.java From morphia with Apache License 2.0 | 5 votes |
@Override public <U> Iterator<U> aggregate(final String collectionName, final Class<U> target, final AggregationOptions options, final ReadPreference readPreference) { LOG.debug("stages = " + stages); AggregateIterable<U> cursor = collection.aggregate(stages, target); return cursor.iterator(); }
Example #5
Source File: MongodbInputDiscoverFieldsImpl.java From pentaho-mongodb-plugin with Apache License 2.0 | 5 votes |
private static Iterator<DBObject> setUpPipelineSample( String query, int numDocsToSample, DBCollection collection ) throws KettleException { query = query + ", {$limit : " + numDocsToSample + "}"; //$NON-NLS-1$ //$NON-NLS-2$ List<DBObject> samplePipe = jsonPipelineToDBObjectList( query ); Cursor cursor = collection.aggregate( samplePipe, AggregationOptions.builder().build() ); return cursor; }
Example #6
Source File: AggregationPipelineImpl.java From morphia with Apache License 2.0 | 4 votes |
@Override public <U> Iterator<U> aggregate(final Class<U> target) { return aggregate(target, AggregationOptions.builder().build(), collection.getReadPreference()); }
Example #7
Source File: AggregationPipelineImpl.java From morphia with Apache License 2.0 | 4 votes |
@Override public <U> Iterator<U> aggregate(final Class<U> target, final AggregationOptions options) { return aggregate(target, options, collection.getReadPreference()); }
Example #8
Source File: AggregationPipelineImpl.java From morphia with Apache License 2.0 | 4 votes |
@Override public <U> Iterator<U> aggregate(final Class<U> target, final AggregationOptions options, final ReadPreference readPreference) { return aggregate(mapper.getCollection(target).getNamespace().getCollectionName(), target, options, readPreference); }
Example #9
Source File: BuguAggregation.java From bugu-mongo with Apache License 2.0 | 4 votes |
public BuguAggregation setOptions(AggregationOptions options){ this.options = options; return this; }
Example #10
Source File: AggregationPipelineImpl.java From morphia with Apache License 2.0 | 4 votes |
@Override public <U> Iterator<U> out(final Class<U> target, final AggregationOptions options) { return out(mapper.getCollection(target).getNamespace().getCollectionName(), target, options); }
Example #11
Source File: AggregationPipelineImpl.java From morphia with Apache License 2.0 | 4 votes |
@Override public <U> Iterator<U> out(final String collectionName, final Class<U> target) { return out(collectionName, target, AggregationOptions.builder().build()); }
Example #12
Source File: AggregationPipelineImpl.java From morphia with Apache License 2.0 | 4 votes |
@Override public <U> Iterator<U> out(final String collectionName, final Class<U> target, final AggregationOptions options) { stages.add(new Document("$out", collectionName)); return aggregate(target, options); }
Example #13
Source File: AggregationPipeline.java From morphia with Apache License 2.0 | 2 votes |
/** * Executes the pipeline and aggregates the output in to the type mapped by the target type. * * <b>Note: This return type will change to {@code MongoCursor} in 2.0 to allow for finer-grained control of iteration and * resource management.</b> * * @param target The class to use when iterating over the results * @param options The options to apply to this aggregation * @param <U> type of the results * @return an iterator of the computed results */ <U> Iterator<U> aggregate(Class<U> target, AggregationOptions options);
Example #14
Source File: AggregationPipeline.java From morphia with Apache License 2.0 | 2 votes |
/** * Executes the pipeline and aggregates the output in to the type mapped by the target type. * * <b>Note: This return type will change to {@code MongoCursor} in 2.0 to allow for finer-grained control of iteration and * resource management.</b> * * @param target The class to use when iterating over the results * @param options The options to apply to this aggregation * @param readPreference The read preference to apply to this pipeline * @param <U> type of the results * @return an iterator of the computed results */ <U> Iterator<U> aggregate(Class<U> target, AggregationOptions options, ReadPreference readPreference);
Example #15
Source File: AggregationPipeline.java From morphia with Apache License 2.0 | 2 votes |
/** * Executes the pipeline and aggregates the output in to the type mapped by the target type. * * <b>Note: This return type will change to {@code MongoCursor} in 2.0 to allow for finer-grained control of iteration and * resource management.</b> * * @param collectionName The collection in which to store the results of the aggregation overriding the mapped value in target * @param target The class to use when iterating over the results * @param options The options to apply to this aggregation * @param readPreference The read preference to apply to this pipeline * @param <U> type of the results * @return an iterator of the computed results */ <U> Iterator<U> aggregate(String collectionName, Class<U> target, AggregationOptions options, ReadPreference readPreference);
Example #16
Source File: AggregationPipeline.java From morphia with Apache License 2.0 | 2 votes |
/** * Places the output of the aggregation in the collection mapped by the target type. * * @param target The class to use when iterating over the results * @param options The options to apply to this aggregation * @param <U> type of the results * @return an iterator of the computed results * @aggregation.expression $out */ <U> Iterator<U> out(Class<U> target, AggregationOptions options);
Example #17
Source File: AggregationPipeline.java From morphia with Apache License 2.0 | 2 votes |
/** * Places the output of the aggregation in the collection mapped by the target type. * * @param collectionName The collection in which to store the results of the aggregation overriding the mapped value in target * @param target The class to use when iterating over the results * @param options The options to apply to this aggregation * @param <U> type of the results * @return an iterator of the computed results * @aggregation.expression $out */ <U> Iterator<U> out(String collectionName, Class<U> target, AggregationOptions options);