Class GeoNear

java.lang.Object
dev.morphia.aggregation.stages.Stage
dev.morphia.aggregation.stages.GeoNear

public class GeoNear extends Stage
Outputs documents in order of nearest to farthest from a specified point.
  • Constructor Details

    • GeoNear

      @MorphiaInternal protected GeoNear(String variable)
  • Method Details

    • geoNear

      public static GeoNear geoNear(String variable)
      Creates a new geoNear stage
      Parameters:
      variable - the variable to use as a reference
      Returns:
      the new stage
      Since:
      3.0
      MongoDB documentation
      Aggregration Pipeline Stage: $geoNear
    • geoNear

      public static GeoNear geoNear(Point point)
      Creates a new geoNear stage
      Parameters:
      point - the center point
      Returns:
      the new stage
      Since:
      2.2
      MongoDB documentation
      Aggregration Pipeline Stage: $geoNear
    • geoNear

      public static GeoNear geoNear(double[] coordinates)
      Creates a new geoNear stage
      Parameters:
      coordinates - the center point coordinates
      Returns:
      the new stage
      Since:
      2.2
      MongoDB documentation
      Aggregration Pipeline Stage: $geoNear
    • distanceField

      public GeoNear distanceField(String distanceField)
      The output field that contains the calculated distance.
      Parameters:
      distanceField - the field name
      Returns:
      this
    • distanceMultiplier

      public GeoNear distanceMultiplier(Number distanceMultiplier)
      Optional. 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 multiplier
      Returns:
      this
    • getVariable

      @Nullable @MorphiaInternal public String getVariable()
    • includeLocs

      public GeoNear includeLocs(String includeLocs)
      Optional. 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.
      Parameters:
      includeLocs - include the field if true
      Returns:
      this
    • key

      public GeoNear key(String key)
      Optional. Specify the geospatial indexed field to use when calculating the distance.
      Parameters:
      key - the indexed field
      Returns:
      this
    • maxDistance

      public GeoNear maxDistance(Number maxDistance)
      Optional. The maximum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall within the specified distance from the center point.

      Specify the distance in meters if the specified point is GeoJSON and in radians if the specified point is legacy coordinate pairs.

      Parameters:
      maxDistance - the max distance
      Returns:
      this
    • minDistance

      public GeoNear minDistance(Number minDistance)
      Optional. The minimum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall outside the specified distance from the center point.

      Specify the distance in meters for GeoJSON data and in radians for legacy coordinate pairs.

      Parameters:
      minDistance - the min distance
      Returns:
      this
    • query

      public GeoNear query(Filter... filters)
      Optional. Limits the results to the documents that match the query.

      You cannot specify a $near predicate in the query field of the $geoNear stage.

      Parameters:
      filters - the filters to apply
      Returns:
      this
    • spherical

      public GeoNear spherical(Boolean spherical)
      Optional. Determines how MongoDB calculates the distance between two points:
      1. When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry.
      2. When false, MongoDB uses $near semantics: spherical geometry for 2dsphere indexes and planar geometry for 2d indexes.
      Parameters:
      spherical - true if spherical
      Returns:
      this