Doctrine\MongoDB\Query\Expr::minDistance PHP Method

minDistance() public method

This method must be called after near() or nearSphere(), since placement of the $minDistance option depends on whether a GeoJSON point or legacy coordinates were provided for $near/$nearSphere.
See also: http://docs.mongodb.org/manual/reference/operator/minDistance/
public minDistance ( float $minDistance )
$minDistance float
    public function minDistance($minDistance)
    {
        if ($this->currentField) {
            $query =& $this->query[$this->currentField];
        } else {
            $query =& $this->query;
        }
        if (!isset($query['$near']) && !isset($query['$nearSphere'])) {
            throw new BadMethodCallException('This method requires a $near or $nearSphere operator (call near() or nearSphere() first)');
        }
        if (isset($query['$near']['$geometry'])) {
            $query['$near']['$minDistance'] = $minDistance;
        } elseif (isset($query['$nearSphere']['$geometry'])) {
            $query['$nearSphere']['$minDistance'] = $minDistance;
        } else {
            $query['$minDistance'] = $minDistance;
        }
        return $this;
    }

Usage Example

Example #1
0
 /**
  * Set the "minDistance" option for a geoNear command query or add
  * $minDistance criteria to the query.
  *
  * If the query is a geoNear command ({@link Expr::geoNear()} was called),
  * the "minDistance" command option will be set; otherwise, $minDistance
  * will be added to the current expression.
  *
  * If the query uses GeoJSON points, $minDistance will be interpreted in
  * meters. If legacy point coordinates are used, $minDistance will be
  * interpreted in radians.
  *
  * @see Expr::minDistance()
  * @see http://docs.mongodb.org/manual/reference/command/geoNear/
  * @see http://docs.mongodb.org/manual/reference/operator/minDistance/
  * @see http://docs.mongodb.org/manual/reference/operator/near/
  * @see http://docs.mongodb.org/manual/reference/operator/nearSphere/
  * @param float $minDistance
  * @return self
  */
 public function minDistance($minDistance)
 {
     if ($this->query['type'] === Query::TYPE_GEO_NEAR) {
         $this->query['geoNear']['options']['minDistance'] = $minDistance;
     } else {
         $this->expr->minDistance($minDistance);
     }
     return $this;
 }
All Usage Examples Of Doctrine\MongoDB\Query\Expr::minDistance