class GraphLookup extends Stage (View source)

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

Properties

protected Builder $builder from Stage

Methods

__construct(Builder $builder, string $from)

Lookup constructor.

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(integer $limit)

Limits the number of documents passed to the next stage in the pipeline.

from Stage
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(integer $size)

Randomly selects the specified number of documents from its input.

from Stage
skip(integer $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, integer|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
createMatchObject()

No description

$this
from(string $from)

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

$this
startWith(string|array|Expr $expression)

Expression that specifies the value of the connectFromField with which to start the recursive search.

$this
connectFromField(string $connectFromField)

Field name whose value $graphLookup uses to recursively match against the connectToField of other documents in the collection.

$this
connectToField(string $connectToField)

Field name in other documents against which to match the value of the field specified by the connectFromField parameter.

$this
alias(string $alias)

Name of the array field added to each output document.

$this
maxDepth(int $maxDepth)

Non-negative integral number specifying the maximum recursion depth.

$this
depthField(string $depthField)

Name of the field to add to each traversed document in the search path.

restrictSearchWithMatch()

A document specifying additional conditions for the recursive search.

string|array
convertExpression(mixed|GraphLookup $expression)

Converts an expression object into an array, recursing into nested items

Details

__construct(Builder $builder, string $from)

Lookup constructor.

Parameters

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

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(integer $limit)

Limits the number of documents passed to the next stage in the pipeline.

Parameters

integer $limit

Return Value

Limit

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/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(integer $size)

Randomly selects the specified number of documents from its input.

Skip skip(integer $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.

Parameters

integer $skip

Return Value

Skip

See also

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

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, integer|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
integer|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/

protected Match createMatchObject()

Return Value

Match

$this from(string $from)

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

The from collection cannot be sharded and must be in the same database as any other collections used in the operation.

Parameters

string $from

Return Value

$this

$this startWith(string|array|Expr $expression)

Expression that specifies the value of the connectFromField with which to start the recursive search.

Optionally, startWith may be array of values, each of which is individually followed through the traversal process.

Parameters

string|array|Expr $expression

Return Value

$this

$this connectFromField(string $connectFromField)

Field name whose value $graphLookup uses to recursively match against the connectToField of other documents in the collection.

Optionally, connectFromField may be an array of field names, each of which is individually followed through the traversal process.

Parameters

string $connectFromField

Return Value

$this

$this connectToField(string $connectToField)

Field name in other documents against which to match the value of the field specified by the connectFromField parameter.

Parameters

string $connectToField

Return Value

$this

$this alias(string $alias)

Name of the array field added to each output document.

Contains the documents traversed in the $graphLookup stage to reach the document.

Parameters

string $alias

Return Value

$this

$this maxDepth(int $maxDepth)

Non-negative integral number specifying the maximum recursion depth.

Parameters

int $maxDepth

Return Value

$this

$this depthField(string $depthField)

Name of the field to add to each traversed document in the search path.

The value of this field is the recursion depth for the document, represented as a NumberLong. Recursion depth value starts at zero, so the first lookup corresponds to zero depth.

Parameters

string $depthField

Return Value

$this

Match restrictSearchWithMatch()

A document specifying additional conditions for the recursive search.

Return Value

Match

protected string|array convertExpression(mixed|GraphLookup $expression)

Converts an expression object into an array, recursing into nested items

This method is meant to be overwritten by extending classes to apply custom conversions (e.g. field name translation in MongoDB ODM) to the expression object.

Parameters

mixed|GraphLookup $expression

Return Value

string|array