Module spring.data.mongodb
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
ConstructorsConstructorDescriptionGeoNearOperation(NearQuery nearQuery, String distanceField) Creates a newGeoNearOperationfrom the givenNearQueryand the given distance field. -
Method Summary
Modifier and TypeMethodDescriptionReturn the MongoDB operator that is used for thisAggregationOperation.org.bson.DocumenttoDocument(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 newGeoNearOperationfrom the givenNearQueryand the given distance field. ThedistanceFielddefines 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:
toDocumentin interfaceAggregationOperation- Parameters:
context- theAggregationOperationContextto operate within. Must not be null.- Returns:
- the Document
-
getOperator
Description copied from interface:AggregationOperationReturn the MongoDB operator that is used for thisAggregationOperation. Aggregation operations should implement this method to avoid document rendering.- Specified by:
getOperatorin interfaceAggregationOperation- Returns:
- the operator used for this
AggregationOperation.
-
toPipelineStages
Description copied from interface:AggregationOperationTurns theAggregationOperationinto list ofstagesby using the givenAggregationOperationContext. This allows a singleAggregationOptionsto add additional stages for eg.$sortor$limit.- Specified by:
toPipelineStagesin interfaceAggregationOperation- Parameters:
context- theAggregationOperationContextto operate within. Must not be null.- Returns:
- the pipeline stages to run through. Never null.
-