Class GeoNearOperation
java.lang.Object
org.springframework.data.mongodb.core.aggregation.GeoNearOperation
- All Implemented Interfaces:
AggregationOperation
Represents a
geoNear
aggregation operation.
We recommend to use the static factory method Aggregation.geoNear(NearQuery, String)
instead of creating
instances of this class directly.
- Since:
- 1.3
- Author:
- Thomas Darimont, Christoph Strobl
- See Also:
-
Constructor Summary
ConstructorDescriptionGeoNearOperation
(NearQuery nearQuery, String distanceField) Creates a newGeoNearOperation
from the givenNearQuery
and the given distance field. -
Method Summary
Modifier and TypeMethodDescriptionReturn the MongoDB operator that is used for thisAggregationOperation
.org.bson.Document
toDocument
(AggregationOperationContext context) List<org.bson.Document>
Optionally specify the geospatial index to use via the field to use in the calculation.
-
Constructor Details
-
GeoNearOperation
Creates a newGeoNearOperation
from the givenNearQuery
and the given distance field. ThedistanceField
defines output field that contains the calculated distance.- Parameters:
nearQuery
- must not be null.distanceField
- must not be null.
-
-
Method Details
-
useIndex
Optionally specify the geospatial index to use via the field to use in the calculation.
NOTE: Requires MongoDB 4.0 or later.- Parameters:
key
- the geospatial index field to use when calculating the distance.- Returns:
- new instance of
GeoNearOperation
. - Since:
- 2.1
-
toDocument
Description copied from interface:AggregationOperation
- Specified by:
toDocument
in interfaceAggregationOperation
- Parameters:
context
- theAggregationOperationContext
to operate within. Must not be null.- Returns:
- the Document
-
getOperator
Description copied from interface:AggregationOperation
Return the MongoDB operator that is used for thisAggregationOperation
. Aggregation operations should implement this method to avoid document rendering.- Specified by:
getOperator
in interfaceAggregationOperation
- Returns:
- the operator used for this
AggregationOperation
.
-
toPipelineStages
Description copied from interface:AggregationOperation
Turns theAggregationOperation
into list ofstages
by using the givenAggregationOperationContext
. This allows a singleAggregationOptions
to add additional stages for eg.$sort
or$limit
.- Specified by:
toPipelineStages
in interfaceAggregationOperation
- Parameters:
context
- theAggregationOperationContext
to operate within. Must not be null.- Returns:
- the pipeline stages to run through. Never null.
-