class GeoNear extends Match (View source)

Fluent interface for adding a $geoNear stage to an aggregation pipeline.

Properties

protected Builder $builder from Stage
protected Expr $query from Match

Methods

__construct(Builder $builder, $x, $y = null)

No description

array
getExpression()

Assembles the aggregation stage

execute(array $options = [])

Executes the aggregation pipeline

from Stage
bucket()

Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.

from Stage
bucketAuto()

Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression.

from Stage
collStats()

Returns statistics regarding a collection or view.

from Stage
count($fieldName)

Returns a document that contains a count of the number of documents input to the stage.

from Stage
facet()

Processes multiple aggregation pipelines within a single stage on the same set of input documents.

from Stage
geoNear(float|array|Point $x, float $y = null)

Outputs documents in order of nearest to farthest from a specified point.

from Stage
array
getPipeline()

Returns the assembled aggregation pipeline

from Stage
graphLookup(string $from)

Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.

from Stage
group()

Groups documents by some specified expression and outputs to the next stage a document for each distinct grouping.

from Stage
indexStats()

Returns statistics regarding the use of each index for the collection.

from Stage
limit(int $limit)

The maximum number of documents to return.

lookup(string $from)

Performs a left outer join to an unsharded collection in the same database to filter in documents from the “joined” collection for processing.

from Stage
match()

Filters the documents to pass only the documents that match the specified condition(s) to the next pipeline stage.

from Stage
Out
out(string $collection)

Takes the documents returned by the aggregation pipeline and writes them to a specified collection. This must be the last stage in the pipeline.

from Stage
project()

Passes along the documents with only the specified fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields.

from Stage
redact()

Restricts the contents of the documents based on information stored in the documents themselves.

from Stage
replaceRoot(string|null $expression = null)

Promotes a specified document to the top level and replaces all other fields.

from Stage
sample(int $size)

Randomly selects the specified number of documents from its input.

from Stage
skip(int $skip)

Skips over the specified number of documents that pass into the stage and passes the remaining documents to the next stage in the pipeline.

from Stage
sortByCount(string $expression)

Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.

from Stage
sort(array|string $fieldName, int|string $order = null)

Sorts all input documents and returns them to the pipeline in sorted order.

from Stage
unwind(string $fieldName)

Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element.

from Stage
__clone()

No description

from Match
$this
addAnd(array|Expr $expression, array|Expr ...$expressions)

Add one or more $and clauses to the current query.

from Match
$this
addNor(array|Expr $expression, array|Expr ...$expressions)

Add one or more $nor clauses to the current query.

from Match
$this
addOr(array|Expr $expression, array|Expr ...$expressions)

Add one or more $or clauses to the current query.

from Match
$this
all(array $values)

Specify $all criteria for the current field.

from Match
mixed
debug(string $name = null)

Return an array of information about the Builder state for debugging.

from Match
$this
elemMatch(array|Expr $expression)

Specify $elemMatch criteria for the current field.

from Match
$this
equals(mixed $value)

Specify an equality match for the current field.

from Match
$this
exists(bool $bool)

Specify $exists criteria for the current field.

from Match
expr()

Create a new Expr instance that can be used to build partial expressions for other operator methods.

from Match
$this
field(string $field)

Set the current field for building the expression.

from Match
$this
geoIntersects(array|Geometry $geometry)

Add $geoIntersects criteria with a GeoJSON geometry to the query.

from Match
$this
geoWithin(Geometry $geometry)

Add $geoWithin criteria with a GeoJSON geometry to the query.

from Match
$this
geoWithinBox(float $x1, float $y1, float $x2, float $y2)

Add $geoWithin criteria with a $box shape to the query.

from Match
$this
geoWithinCenter(float $x, float $y, float $radius)

Add $geoWithin criteria with a $center shape to the query.

from Match
$this
geoWithinCenterSphere(float $x, float $y, float $radius)

Add $geoWithin criteria with a $centerSphere shape to the query.

from Match
$this
geoWithinPolygon(array $point1, array $point2, array $point3, array ...$points)

Add $geoWithin criteria with a $polygon shape to the query.

from Match
$this
gt(mixed $value)

Specify $gt criteria for the current field.

from Match
$this
gte(mixed $value)

Specify $gte criteria for the current field.

from Match
$this
in(array $values)

Specify $in criteria for the current field.

from Match
$this
includesReferenceTo(object $document)

No description

from Match
$this
language(string $language)

Set the $language option for $text criteria.

from Match
$this
lt(mixed $value)

Specify $lt criteria for the current field.

from Match
$this
lte(mixed $value)

Specify $lte criteria for the current field.

from Match
$this
maxDistance(float $maxDistance)

The maximum distance from the center point that the documents can be.

$this
minDistance(float $minDistance)

The minimum distance from the center point that the documents can be.

$this
mod(float|int $divisor, float|int $remainder = 0)

Specify $mod criteria for the current field.

from Match
$this
not(array|Expr $expression)

Negates an expression for the current field.

from Match
$this
notEqual(mixed $value)

Specify $ne criteria for the current field.

from Match
$this
notIn(array $values)

Specify $nin criteria for the current field.

from Match
$this
range(mixed $start, mixed $end)

Specify $gte and $lt criteria for the current field.

from Match
$this
references(object $document)

No description

from Match
$this
size(int $size)

Specify $size criteria for the current field.

from Match
$this
text(string $search)

Specify $text criteria for the current field.

from Match
$this
type(int $type)

Specify $type criteria for the current field.

from Match
$this
distanceField(string $distanceField)

The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation.

$this
distanceMultiplier(float $distanceMultiplier)

The factor to multiply all distances returned by the query.

$this
includeLocs(string $includeLocs)

This specifies the output field that identifies the location used to calculate the distance.

$this
near(float|array|Point $x, float $y = null)

The point for which to find the closest documents.

$this
num(int $num)

The maximum number of documents to return.

$this
spherical(bool $spherical = true)

Required if using a 2dsphere index. Determines how MongoDB calculates the distance.

$this
uniqueDocs(bool $uniqueDocs = true)

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.

Details

__construct(Builder $builder, $x, $y = null)

Parameters

Builder $builder
$x
$y

array getExpression()

Assembles the aggregation stage

Return Value

array

Iterator execute(array $options = [])

Executes the aggregation pipeline

Parameters

array $options

Return Value

Iterator

Bucket bucket()

Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.

Each bucket is represented as a document in the output. The document for each bucket contains an _id field, whose value specifies the inclusive lower bound of the bucket and a count field that contains the number of documents in the bucket. The count field is included by default when the output is not specified.

BucketAuto bucketAuto()

Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression.

Bucket boundaries are automatically determined in an attempt to evenly distribute the documents into the specified number of buckets. Each bucket is represented as a document in the output. The document for each bucket contains an _id field, whose value specifies the inclusive lower bound and the exclusive upper bound for the bucket, and a count field that contains the number of documents in the bucket. The count field is included by default when the output is not specified.

CollStats collStats()

Returns statistics regarding a collection or view.

$collStats must be the first stage in an aggregation pipeline, or else the pipeline returns an error.

Count count($fieldName)

Returns a document that contains a count of the number of documents input to the stage.

Facet facet()

Processes multiple aggregation pipelines within a single stage on the same set of input documents.

Each sub-pipeline has its own field in the output document where its results are stored as an array of documents.

Return Value

Facet

GeoNear geoNear(float|array|Point $x, float $y = null)

Outputs documents in order of nearest to farthest from a specified point.

You can only use this as the first stage of a pipeline.

Parameters

float|array|Point $x
float $y

Return Value

GeoNear

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/geoNear/

array getPipeline()

Returns the assembled aggregation pipeline

Return Value

array

GraphLookup graphLookup(string $from)

Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.

Parameters

string $from Target collection for the $graphLookup operation to search, recursively matching the connectFromField to the connectToField.

Return Value

GraphLookup

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/graphLookup/

Group group()

Groups documents by some specified expression and outputs to the next stage a document for each distinct grouping.

IndexStats indexStats()

Returns statistics regarding the use of each index for the collection.

Limit limit(int $limit)

The maximum number of documents to return.

Parameters

int $limit

Return Value

Limit

Lookup lookup(string $from)

Performs a left outer join to an unsharded collection in the same database to filter in documents from the “joined” collection for processing.

Match match()

Filters the documents to pass only the documents that match the specified condition(s) to the next pipeline stage.

Out out(string $collection)

Takes the documents returned by the aggregation pipeline and writes them to a specified collection. This must be the last stage in the pipeline.

Parameters

string $collection

Return Value

Out

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/out/

Project project()

Passes along the documents with only the specified fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields.

Redact redact()

Restricts the contents of the documents based on information stored in the documents themselves.

ReplaceRoot replaceRoot(string|null $expression = null)

Promotes a specified document to the top level and replaces all other fields.

The operation replaces all existing fields in the input document, including the _id field. You can promote an existing embedded document to the top level, or create a new document for promotion.

Parameters

string|null $expression Optional. A replacement expression that resolves to a document.

Return Value

ReplaceRoot

Sample sample(int $size)

Randomly selects the specified number of documents from its input.

Skip skip(int $skip)

Skips over the specified number of documents that pass into the stage and passes the remaining documents to the next stage in the pipeline.

SortByCount sortByCount(string $expression)

Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.

Parameters

string $expression The expression to group by

Return Value

SortByCount

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/sortByCount/

Sort sort(array|string $fieldName, int|string $order = null)

Sorts all input documents and returns them to the pipeline in sorted order.

If sorting by multiple fields, the first argument should be an array of field name (key) and order (value) pairs.

Parameters

array|string $fieldName Field name or array of field/order pairs
int|string $order Field order (if one field is specified)

Return Value

Sort

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/sort/

Unwind unwind(string $fieldName)

Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element.

Parameters

string $fieldName The field to unwind. It is automatically prefixed with the $ sign

Return Value

Unwind

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/unwind/

$this addAnd(array|Expr $expression, array|Expr ...$expressions)

Add one or more $and clauses to the current query.

You can create a new expression using the {@link Builder::matchExpr()} method.

Parameters

array|Expr $expression
array|Expr ...$expressions

Return Value

$this

See also

Expr::addAnd
http://docs.mongodb.org/manual/reference/operator/and/

$this addNor(array|Expr $expression, array|Expr ...$expressions)

Add one or more $nor clauses to the current query.

You can create a new expression using the {@link Builder::matchExpr()} method.

Parameters

array|Expr $expression
array|Expr ...$expressions

Return Value

$this

See also

Expr::addNor
http://docs.mongodb.org/manual/reference/operator/nor/

$this addOr(array|Expr $expression, array|Expr ...$expressions)

Add one or more $or clauses to the current query.

You can create a new expression using the {@link Builder::matchExpr()} method.

Parameters

array|Expr $expression
array|Expr ...$expressions

Return Value

$this

See also

Expr::addOr
http://docs.mongodb.org/manual/reference/operator/or/

$this all(array $values)

Specify $all criteria for the current field.

Parameters

array $values

Return Value

$this

See also

Expr::all
http://docs.mongodb.org/manual/reference/operator/all/

mixed debug(string $name = null)

Return an array of information about the Builder state for debugging.

The $name parameter may be used to return a specific key from the internal $query array property. If omitted, the entire array will be returned.

Parameters

string $name

Return Value

mixed

$this elemMatch(array|Expr $expression)

Specify $elemMatch criteria for the current field.

You can create a new expression using the {@link Builder::matchExpr()} method.

Parameters

array|Expr $expression

Return Value

$this

See also

Expr::elemMatch
http://docs.mongodb.org/manual/reference/operator/elemMatch/

$this equals(mixed $value)

Specify an equality match for the current field.

Parameters

mixed $value

Return Value

$this

See also

Expr::equals

$this exists(bool $bool)

Specify $exists criteria for the current field.

Parameters

bool $bool

Return Value

$this

See also

Expr::exists
http://docs.mongodb.org/manual/reference/operator/exists/

Expr expr()

Create a new Expr instance that can be used to build partial expressions for other operator methods.

Return Value

Expr $expr

$this field(string $field)

Set the current field for building the expression.

Parameters

string $field

Return Value

$this

See also

Expr::field

$this geoIntersects(array|Geometry $geometry)

Add $geoIntersects criteria with a GeoJSON geometry to the query.

The geometry parameter GeoJSON object or an array corresponding to the geometry's JSON representation.

Parameters

array|Geometry $geometry

Return Value

$this

See also

Expr::geoIntersects
http://docs.mongodb.org/manual/reference/operator/geoIntersects/

$this geoWithin(Geometry $geometry)

Add $geoWithin criteria with a GeoJSON geometry to the query.

The geometry parameter GeoJSON object or an array corresponding to the geometry's JSON representation.

Parameters

Geometry $geometry

Return Value

$this

See also

Expr::geoWithin
http://docs.mongodb.org/manual/reference/operator/geoWithin/

$this geoWithinBox(float $x1, float $y1, float $x2, float $y2)

Add $geoWithin criteria with a $box shape to the query.

A rectangular polygon will be constructed from a pair of coordinates corresponding to the bottom left and top right corners.

Note: the $box operator only supports legacy coordinate pairs and 2d indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.

Parameters

float $x1
float $y1
float $x2
float $y2

Return Value

$this

See also

Expr::geoWithinBox
http://docs.mongodb.org/manual/reference/operator/box/

$this geoWithinCenter(float $x, float $y, float $radius)

Add $geoWithin criteria with a $center shape to the query.

Note: the $center operator only supports legacy coordinate pairs and 2d indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.

Parameters

float $x
float $y
float $radius

Return Value

$this

See also

Expr::geoWithinCenter
http://docs.mongodb.org/manual/reference/operator/center/

$this geoWithinCenterSphere(float $x, float $y, float $radius)

Add $geoWithin criteria with a $centerSphere shape to the query.

Note: the $centerSphere operator supports both 2d and 2dsphere indexes.

Parameters

float $x
float $y
float $radius

Return Value

$this

See also

Expr::geoWithinCenterSphere
http://docs.mongodb.org/manual/reference/operator/centerSphere/

$this geoWithinPolygon(array $point1, array $point2, array $point3, array ...$points)

Add $geoWithin criteria with a $polygon shape to the query.

Point coordinates are in x, y order (easting, northing for projected coordinates, longitude, latitude for geographic coordinates).

The last point coordinate is implicitly connected with the first.

Note: the $polygon operator only supports legacy coordinate pairs and 2d indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.

Parameters

array $point1 First point of the polygon
array $point2 Second point of the polygon
array $point3 Third point of the polygon
array ...$points Additional points of the polygon

Return Value

$this

See also

Expr::geoWithinPolygon
http://docs.mongodb.org/manual/reference/operator/polygon/

$this gt(mixed $value)

Specify $gt criteria for the current field.

Parameters

mixed $value

Return Value

$this

See also

Expr::gt
http://docs.mongodb.org/manual/reference/operator/gt/

$this gte(mixed $value)

Specify $gte criteria for the current field.

Parameters

mixed $value

Return Value

$this

See also

Expr::gte
http://docs.mongodb.org/manual/reference/operator/gte/

$this in(array $values)

Specify $in criteria for the current field.

Parameters

array $values

Return Value

$this

See also

Expr::in
http://docs.mongodb.org/manual/reference/operator/in/

$this includesReferenceTo(object $document)

Parameters

object $document

Return Value

$this

$this language(string $language)

Set the $language option for $text criteria.

This method must be called after text().

Parameters

string $language

Return Value

$this

See also

Expr::language
http://docs.mongodb.org/manual/reference/operator/text/

$this lt(mixed $value)

Specify $lt criteria for the current field.

Parameters

mixed $value

Return Value

$this

See also

Expr::lte
http://docs.mongodb.org/manual/reference/operator/lte/

$this lte(mixed $value)

Specify $lte criteria for the current field.

Parameters

mixed $value

Return Value

$this

See also

Expr::lte
http://docs.mongodb.org/manual/reference/operator/lte/

$this maxDistance(float $maxDistance)

The maximum distance from the center point that the documents can be.

Parameters

float $maxDistance

Return Value

$this

$this minDistance(float $minDistance)

The minimum distance from the center point that the documents can be.

Parameters

float $minDistance

Return Value

$this

$this mod(float|int $divisor, float|int $remainder = 0)

Specify $mod criteria for the current field.

Parameters

float|int $divisor
float|int $remainder

Return Value

$this

See also

Expr::mod
http://docs.mongodb.org/manual/reference/operator/mod/

$this not(array|Expr $expression)

Negates an expression for the current field.

You can create a new expression using the {@link Builder::matchExpr()} method.

Parameters

array|Expr $expression

Return Value

$this

See also

Expr::not
http://docs.mongodb.org/manual/reference/operator/not/

$this notEqual(mixed $value)

Specify $ne criteria for the current field.

Parameters

mixed $value

Return Value

$this

See also

Expr::notEqual
http://docs.mongodb.org/manual/reference/operator/ne/

$this notIn(array $values)

Specify $nin criteria for the current field.

Parameters

array $values

Return Value

$this

See also

Expr::notIn
http://docs.mongodb.org/manual/reference/operator/nin/

$this range(mixed $start, mixed $end)

Specify $gte and $lt criteria for the current field.

This method is shorthand for specifying $gte criteria on the lower bound and $lt criteria on the upper bound. The upper bound is not inclusive.

Parameters

mixed $start
mixed $end

Return Value

$this

See also

Expr::range

$this references(object $document)

Parameters

object $document

Return Value

$this

$this size(int $size)

Specify $size criteria for the current field.

Parameters

int $size

Return Value

$this

See also

Expr::size
http://docs.mongodb.org/manual/reference/operator/size/

$this text(string $search)

Specify $text criteria for the current field.

The $language option may be set with {@link Builder::language()}.

You can only use this in the first $match stage of a pipeline.

Parameters

string $search

Return Value

$this

See also

Expr::text
http://docs.mongodb.org/master/reference/operator/query/text/

$this type(int $type)

Specify $type criteria for the current field.

Parameters

int $type

Return Value

$this

See also

Expr::type
http://docs.mongodb.org/manual/reference/operator/type/

$this distanceField(string $distanceField)

The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation.

Parameters

string $distanceField

Return Value

$this

$this distanceMultiplier(float $distanceMultiplier)

The factor to multiply all distances returned by the query.

Parameters

float $distanceMultiplier

Return Value

$this

$this includeLocs(string $includeLocs)

This specifies the output field that identifies the location used to calculate the distance.

Parameters

string $includeLocs

Return Value

$this

$this near(float|array|Point $x, float $y = null)

The point for which to find the closest documents.

A GeoJSON point may be provided as the first and only argument for 2dsphere queries. This single parameter may be a GeoJSON point object or an array corresponding to the point's JSON representation. If GeoJSON is used, the "spherical" option will default to true.

Parameters

float|array|Point $x
float $y

Return Value

$this

$this num(int $num)

The maximum number of documents to return.

Parameters

int $num

Return Value

$this

$this spherical(bool $spherical = true)

Required if using a 2dsphere index. Determines how MongoDB calculates the distance.

Parameters

bool $spherical

Return Value

$this

$this uniqueDocs(bool $uniqueDocs = true)

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.

Parameters

bool $uniqueDocs

Return Value

$this