Package dev.morphia.aggregation
Class GeoNear.GeoNearBuilder
- java.lang.Object
-
- dev.morphia.aggregation.GeoNear.GeoNearBuilder
-
- Enclosing class:
- GeoNear
public static class GeoNear.GeoNearBuilder extends java.lang.Object
Provides a builder for GeoNear instances.
-
-
Constructor Summary
Constructors Constructor Description GeoNearBuilder(java.lang.String distanceField)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description GeoNear
build()
GeoNear.GeoNearBuilder
setDistanceMultiplier(java.lang.Double distanceMultiplier)
The factor to multiply all distances returned by the query.GeoNear.GeoNearBuilder
setIncludeLocations(java.lang.String includeLocations)
This specifies the output field that identifies the location used to calculate the distance.GeoNear.GeoNearBuilder
setLimit(java.lang.Long limit)
The maximum number of documents to return.GeoNear.GeoNearBuilder
setMaxDistance(java.lang.Double maxDistance)
A distance from the center point.GeoNear.GeoNearBuilder
setMaxDocuments(java.lang.Long num)
The maxDocuments option provides the same function as the limit option.GeoNear.GeoNearBuilder
setNear(double latitude, double longitude)
Sets the point for which to find the closest documents.GeoNear.GeoNearBuilder
setNear(Point point)
Sets the point for which to find the closest documents.GeoNear.GeoNearBuilder
setQuery(Query query)
Limits the results to the documents that match the query.GeoNear.GeoNearBuilder
setSpherical(java.lang.Boolean spherical)
If true, MongoDB references points using a spherical surface.GeoNear.GeoNearBuilder
setUniqueDocuments(java.lang.Boolean uniqueDocuments)
Deprecated.Deprecated since server version 2.6: Geospatial queries no longer return duplicate results.
-
-
-
Constructor Detail
-
GeoNearBuilder
public GeoNearBuilder(java.lang.String distanceField)
- Parameters:
distanceField
- The output field that contains the calculated distance. To specify a field within a subdocument, use dot notation.- See Also:
- dot notation
-
-
Method Detail
-
build
public GeoNear build()
- Returns:
- the GeoNear instance as configured by this builder
-
setDistanceMultiplier
public GeoNear.GeoNearBuilder setDistanceMultiplier(java.lang.Double distanceMultiplier)
The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth.- Parameters:
distanceMultiplier
- the distance multiplier used in this stage- Returns:
- this
-
setIncludeLocations
public GeoNear.GeoNearBuilder setIncludeLocations(java.lang.String includeLocations)
This specifies the output field that identifies the location used to calculate the distance. This option is useful when a location field contains multiple locations. To specify a field within a subdocument, use dot notation.- Parameters:
includeLocations
- the output field that identifies the location used to calculate the distance- Returns:
- this
- See Also:
- dot notation
-
setLimit
public GeoNear.GeoNearBuilder setLimit(java.lang.Long limit)
The maximum number of documents to return. The default value is 100.- Parameters:
limit
- the maximum- Returns:
- this
-
setMaxDistance
public GeoNear.GeoNearBuilder setMaxDistance(java.lang.Double maxDistance)
A distance from the center point. Specify the distance in radians. MongoDB limits the results to those documents that fall within the specified distance from the center point.- Parameters:
maxDistance
- the maximum- Returns:
- this
-
setMaxDocuments
public GeoNear.GeoNearBuilder setMaxDocuments(java.lang.Long num)
The maxDocuments option provides the same function as the limit option. Both define the maximum number of documents to return. If both options are included, this value overrides the limit value.- Parameters:
num
- the maximum- Returns:
- this
-
setNear
public GeoNear.GeoNearBuilder setNear(double latitude, double longitude)
Sets the point for which to find the closest documents.- Parameters:
latitude
- the latitudelongitude
- the longitude- Returns:
- this
-
setNear
public GeoNear.GeoNearBuilder setNear(Point point)
Sets the point for which to find the closest documents.- Parameters:
point
- a GeoJSON single point location.- Returns:
- this
-
setQuery
public GeoNear.GeoNearBuilder setQuery(Query query)
Limits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax.- Parameters:
query
- the query used to limit the documents to consider- Returns:
- this
- MongoDB documentation
- tutorial/query-documents/ read operation query syntax
-
setSpherical
public GeoNear.GeoNearBuilder setSpherical(java.lang.Boolean spherical)
If true, MongoDB references points using a spherical surface. The default value is false.- Parameters:
spherical
- true if spherical geometry should be used- Returns:
- this
-
setUniqueDocuments
@Deprecated public GeoNear.GeoNearBuilder setUniqueDocuments(java.lang.Boolean uniqueDocuments)
Deprecated.Deprecated since server version 2.6: Geospatial queries no longer return duplicate results. The $uniqueDocs operator has no impact on results.If this value is true, the query returns a matching document once, even if more than one of the document's location fields match the query. If this value is false, the query returns a document multiple times if the document has multiple matching location fields. See $uniqueDocs for more information.- Parameters:
uniqueDocuments
- true if only unique documents are required in the return value- Returns:
- this builder
- See Also:
- uniqueDocs
-
-