use of org.springframework.data.mongodb.core.mapreduce.MapReduceOptions in project spring-data-mongodb by spring-projects.
the class MongoTemplateUnitTests method mapReduceShouldPickUpLimitFromOptionsEvenWhenQueryDefinesItDifferently.
// DATAMONGO-1334
@Test
void mapReduceShouldPickUpLimitFromOptionsEvenWhenQueryDefinesItDifferently() {
MongoCursor cursor = mock(MongoCursor.class);
MapReduceIterable output = mock(MapReduceIterable.class);
when(output.limit(anyInt())).thenReturn(output);
when(output.sort(any())).thenReturn(output);
when(output.filter(any(Document.class))).thenReturn(output);
when(output.iterator()).thenReturn(cursor);
when(cursor.hasNext()).thenReturn(false);
when(collection.mapReduce(anyString(), anyString(), eq(Document.class))).thenReturn(output);
Query query = new BasicQuery("{'foo':'bar'}");
query.limit(100);
template.mapReduce(query, "collection", "function(){}", "function(key,values){}", new MapReduceOptions().limit(1000), Wrapper.class);
verify(output, times(1)).limit(1000);
}
use of org.springframework.data.mongodb.core.mapreduce.MapReduceOptions in project spring-data-mongodb by spring-projects.
the class MapReduceTests method performMapReduce.
private void performMapReduce(boolean inline, boolean withQuery) {
createMapReduceData();
MapReduceResults<ValueObject> results;
if (inline) {
if (withQuery) {
results = mongoTemplate.mapReduce(new Query(), "jmr1", "classpath:map.js", "classpath:reduce.js", ValueObject.class);
} else {
results = mongoTemplate.mapReduce("jmr1", MAP_FUNCTION, REDUCE_FUNCTION, ValueObject.class);
}
} else {
if (withQuery) {
results = mongoTemplate.mapReduce(new Query(), "jmr1", MAP_FUNCTION, REDUCE_FUNCTION, options().outputCollection("jmr1_out"), ValueObject.class);
} else {
results = mongoTemplate.mapReduce("jmr1", MAP_FUNCTION, REDUCE_FUNCTION, new MapReduceOptions().outputCollection("jmr1_out"), ValueObject.class);
}
}
assertMapReduceResults(copyToMap(results));
}
Aggregations