@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2013 the original author or authors .
* Copyright 2013 - 2015 the original author or authors .
*
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -47,11 +47,14 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.dao.DataAccessException ;
import org.springframework.dao.DataAccessException ;
import org.springframework.data.annotation.Id ;
import org.springframework.data.annotation.Id ;
import org.springframework.data.domain.Sort.Direction ;
import org.springframework.data.domain.Sort.Direction ;
import org.springframework.data.geo.Metrics ;
import org.springframework.data.mapping.model.MappingException ;
import org.springframework.data.mapping.model.MappingException ;
import org.springframework.data.mongodb.core.CollectionCallback ;
import org.springframework.data.mongodb.core.CollectionCallback ;
import org.springframework.data.mongodb.core.MongoTemplate ;
import org.springframework.data.mongodb.core.MongoTemplate ;
import org.springframework.data.mongodb.core.Venue ;
import org.springframework.data.mongodb.core.aggregation.AggregationTests.CarDescriptor.Entry ;
import org.springframework.data.mongodb.core.aggregation.AggregationTests.CarDescriptor.Entry ;
import org.springframework.data.mongodb.core.mapping.Document ;
import org.springframework.data.mongodb.core.index.GeospatialIndex ;
import org.springframework.data.mongodb.core.query.NearQuery ;
import org.springframework.data.mongodb.core.query.Query ;
import org.springframework.data.mongodb.core.query.Query ;
import org.springframework.data.mongodb.repository.Person ;
import org.springframework.data.mongodb.repository.Person ;
import org.springframework.data.util.Version ;
import org.springframework.data.util.Version ;
@ -120,6 +123,7 @@ public class AggregationTests {
mongoTemplate . dropCollection ( User . class ) ;
mongoTemplate . dropCollection ( User . class ) ;
mongoTemplate . dropCollection ( Person . class ) ;
mongoTemplate . dropCollection ( Person . class ) ;
mongoTemplate . dropCollection ( Reservation . class ) ;
mongoTemplate . dropCollection ( Reservation . class ) ;
mongoTemplate . dropCollection ( Venue . class ) ;
}
}
/ * *
/ * *
@ -1018,6 +1022,30 @@ public class AggregationTests {
assertThat ( dbo . get ( "dayOfYearPlus1DayManually" ) , is ( ( Object ) dateTime . plusDays ( 1 ) . getDayOfYear ( ) ) ) ;
assertThat ( dbo . get ( "dayOfYearPlus1DayManually" ) , is ( ( Object ) dateTime . plusDays ( 1 ) . getDayOfYear ( ) ) ) ;
}
}
/ * *
* @see DATAMONGO - 1127
* /
@Test
public void shouldSupportGeoNearQueriesForAggregationWithDistanceField ( ) {
mongoTemplate . insert ( new Venue ( "Penn Station" , - 73 . 99408 , 40 . 75057 ) ) ;
mongoTemplate . insert ( new Venue ( "10gen Office" , - 73 . 99171 , 40 . 738868 ) ) ;
mongoTemplate . insert ( new Venue ( "Flatiron Building" , - 73 . 988135 , 40 . 741404 ) ) ;
mongoTemplate . indexOps ( Venue . class ) . ensureIndex ( new GeospatialIndex ( "location" ) ) ;
NearQuery geoNear = NearQuery . near ( - 73 , 40 , Metrics . KILOMETERS ) . num ( 10 ) . maxDistance ( 150 ) ;
Aggregation agg = newAggregation ( Aggregation . geoNear ( geoNear , "distance" ) ) ;
AggregationResults < DBObject > result = mongoTemplate . aggregate ( agg , Venue . class , DBObject . class ) ;
assertThat ( result . getMappedResults ( ) , hasSize ( 3 ) ) ;
DBObject firstResult = result . getMappedResults ( ) . get ( 0 ) ;
assertThat ( firstResult . containsField ( "distance" ) , is ( true ) ) ;
assertThat ( firstResult . get ( "distance" ) , is ( ( Object ) 117 . 620092203928 ) ) ;
}
private void assertLikeStats ( LikeStats like , String id , long count ) {
private void assertLikeStats ( LikeStats like , String id , long count ) {
assertThat ( like , is ( notNullValue ( ) ) ) ;
assertThat ( like , is ( notNullValue ( ) ) ) ;