FluentFactoryTrait
Table of Contents
Properties
- $pipeline : array<int, StageInterface|array<string, mixed>|stdClass>
Methods
- addFields() : static
- Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields.
- bucket() : static
- Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.
- bucketAuto() : static
- 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.
- changeStream() : static
- Returns a Change Stream cursor for the collection or database. This stage can only occur once in an aggregation pipeline and it must occur as the first stage.
- changeStreamSplitLargeEvent() : static
- Splits large change stream events that exceed 16 MB into smaller fragments returned in a change stream cursor.
- collStats() : static
- Returns statistics regarding a collection or view.
- count() : static
- Returns a count of the number of documents at this stage of the aggregation pipeline.
- currentOp() : static
- Returns information on active and/or dormant operations for the MongoDB deployment. To run, use the db.aggregate() method.
- densify() : static
- Creates new documents in a sequence of documents where certain values in a field are missing.
- documents() : static
- Returns literal documents from input values.
- facet() : static
- Processes multiple aggregation pipelines within a single stage on the same set of input documents. Enables the creation of multi-faceted aggregations capable of characterizing data across multiple dimensions, or facets, in a single stage.
- fill() : static
- Populates null and missing field values within documents.
- geoNear() : static
- Returns an ordered stream of documents based on the proximity to a geospatial point. Incorporates the functionality of $match, $sort, and $limit for geospatial data. The output documents include an additional distance field and can include a location identifier field.
- getPipeline() : Pipeline
- graphLookup() : static
- Performs a recursive search on a collection. To each output document, adds a new array field that contains the traversal results of the recursive search for that document.
- group() : static
- Groups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group. Consumes all input documents and outputs one document per each distinct group. The output documents only contain the identifier field and, if specified, accumulated fields.
- indexStats() : static
- Returns statistics regarding the use of each index for the collection.
- limit() : static
- Passes the first n documents unmodified to the pipeline where n is the specified limit. For each input document, outputs either one document (for the first n documents) or zero documents (after the first n documents).
- listLocalSessions() : static
- Lists all active sessions recently in use on the currently connected mongos or mongod instance. These sessions may have not yet propagated to the system.sessions collection.
- listSampledQueries() : static
- Lists sampled queries for all collections or a specific collection.
- listSearchIndexes() : static
- Returns information about existing Atlas Search indexes on a specified collection.
- listSessions() : static
- Lists all sessions that have been active long enough to propagate to the system.sessions collection.
- lookup() : static
- Performs a left outer join to another collection in the same database to filter in documents from the "joined" collection for processing.
- match() : static
- Filters the document stream to allow only matching documents to pass unmodified into the next pipeline stage. $match uses standard MongoDB queries. For each input document, outputs either one document (a match) or zero documents (no match).
- merge() : static
- Writes the resulting documents of the aggregation pipeline to a collection. The stage can incorporate (insert new documents, merge documents, replace documents, keep existing documents, fail the operation, process documents with a custom update pipeline) the results into an output collection. To use the $merge stage, it must be the last stage in the pipeline.
- out() : static
- Writes the resulting documents of the aggregation pipeline to a collection. To use the $out stage, it must be the last stage in the pipeline.
- planCacheStats() : static
- Returns plan cache information for a collection.
- project() : static
- Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document.
- redact() : static
- Reshapes each document in the stream by restricting the content for each document based on information stored in the documents themselves. Incorporates the functionality of $project and $match. Can be used to implement field level redaction. For each input document, outputs either one or zero documents.
- replaceRoot() : static
- Replaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the _id field. Specify a document embedded in the input document to promote the embedded document to the top level.
- replaceWith() : static
- Replaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the _id field. Specify a document embedded in the input document to promote the embedded document to the top level.
- sample() : static
- Randomly selects the specified number of documents from its input.
- scoreFusion() : static
- Combines multiple pipelines using relative score fusion to create hybrid search results.
- search() : static
- Performs a full-text search of the field or fields in an Atlas collection.
- searchMeta() : static
- Returns different types of metadata result documents for the Atlas Search query against an Atlas collection.
- set() : static
- Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields.
- setWindowFields() : static
- Groups documents into windows and applies one or more operators to the documents in each window.
- shardedDataDistribution() : static
- Provides data and size distribution information on sharded collections.
- skip() : static
- Skips the first n documents where n is the specified skip number and passes the remaining documents unmodified to the pipeline. For each input document, outputs either zero documents (for the first n documents) or one document (if after the first n documents).
- sort() : static
- Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document.
- sortByCount() : static
- Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.
- unionWith() : static
- Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set.
- unset() : static
- Removes or excludes fields from documents.
- unwind() : static
- Deconstructs an array field from the input documents to output a document for each element. Each output document replaces the array with an element value. For each input document, outputs n documents where n is the number of array elements and can be zero for an empty array.
- vectorSearch() : static
- The $vectorSearch stage performs an ANN or ENN search on a vector in the specified field.
Properties
$pipeline
public
array<int, StageInterface|array<string, mixed>|stdClass>
$pipeline
= []
Methods
addFields()
Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields.
public
addFields(DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string ...$expression) : static
Parameters
- $expression : DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string
-
Specify the name of each field to add and set its value to an aggregation expression or an empty object.
Tags
Return values
staticbucket()
Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.
public
bucket(DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string $groupBy, BSONArray|PackedArray|array<string|int, mixed> $boundaries[, Optional|DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string $default = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $output = Optional::Undefined ]) : static
Parameters
- $groupBy : DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string
-
An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. Unless $bucket includes a default specification, each input document must resolve the groupBy field path or expression to a value that falls within one of the ranges specified by the boundaries.
- $boundaries : BSONArray|PackedArray|array<string|int, mixed>
-
An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. The specified values must be in ascending order and all of the same type. The exception is if the values are of mixed numeric types, such as:
- $default : Optional|DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string = Optional::Undefined
-
A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. If unspecified, each input document must resolve the groupBy expression to a value within one of the bucket ranges specified by boundaries or the operation throws an error. The default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value. The default value can be of a different type than the entries in boundaries.
- $output : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. If you do not specify an output document, the operation returns a count field containing the number of documents in each bucket. If you specify an output document, only the fields specified in the document are returned; i.e. the count field is not returned unless it is explicitly included in the output document.
Tags
Return values
staticbucketAuto()
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.
public
bucketAuto(DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string $groupBy, int $buckets[, Optional|Document|Serializable|array<string|int, mixed>|stdClass $output = Optional::Undefined ][, Optional|string $granularity = Optional::Undefined ]) : static
Parameters
- $groupBy : DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string
-
An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes.
- $buckets : int
-
A positive 32-bit integer that specifies the number of buckets into which input documents are grouped.
- $output : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it.
- $granularity : Optional|string = Optional::Undefined
-
A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. Available only if the all groupBy values are numeric and none of them are NaN.
Tags
Return values
staticchangeStream()
Returns a Change Stream cursor for the collection or database. This stage can only occur once in an aggregation pipeline and it must occur as the first stage.
public
changeStream([Optional|bool $allChangesForCluster = Optional::Undefined ][, Optional|string $fullDocument = Optional::Undefined ][, Optional|string $fullDocumentBeforeChange = Optional::Undefined ][, Optional|int $resumeAfter = Optional::Undefined ][, Optional|bool $showExpandedEvents = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $startAfter = Optional::Undefined ][, Optional|Timestamp|int $startAtOperationTime = Optional::Undefined ]) : static
Parameters
- $allChangesForCluster : Optional|bool = Optional::Undefined
-
A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections.
- $fullDocument : Optional|string = Optional::Undefined
-
Specifies whether change notifications include a copy of the full document when modified by update operations.
- $fullDocumentBeforeChange : Optional|string = Optional::Undefined
-
Valid values are "off", "whenAvailable", or "required". If set to "off", the "fullDocumentBeforeChange" field of the output document is always omitted. If set to "whenAvailable", the "fullDocumentBeforeChange" field will be populated with the pre-image of the document modified by the current change event if such a pre-image is available, and will be omitted otherwise. If set to "required", then the "fullDocumentBeforeChange" field is always populated and an exception is thrown if the pre-image is not available.
- $resumeAfter : Optional|int = Optional::Undefined
-
Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields.
- $showExpandedEvents : Optional|bool = Optional::Undefined
-
Specifies whether to include additional change events, such as such as DDL and index operations. New in MongoDB 6.0.
- $startAfter : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields.
- $startAtOperationTime : Optional|Timestamp|int = Optional::Undefined
-
Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields.
Tags
Return values
staticchangeStreamSplitLargeEvent()
Splits large change stream events that exceed 16 MB into smaller fragments returned in a change stream cursor.
public
changeStreamSplitLargeEvent() : static
You can only use $changeStreamSplitLargeEvent in a $changeStream pipeline and it must be the final stage in the pipeline.
Tags
Return values
staticcollStats()
Returns statistics regarding a collection or view.
public
collStats([Optional|Document|Serializable|array<string|int, mixed>|stdClass $latencyStats = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $storageStats = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $count = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $queryExecStats = Optional::Undefined ]) : static
Parameters
- $latencyStats : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
- $storageStats : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
- $count : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
- $queryExecStats : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
Tags
Return values
staticcount()
Returns a count of the number of documents at this stage of the aggregation pipeline.
public
count(string $field) : static
Distinct from the $count aggregation accumulator.
Parameters
- $field : string
-
Name of the output field which has the count as its value. It must be a non-empty string, must not start with $ and must not contain the . character.
Tags
Return values
staticcurrentOp()
Returns information on active and/or dormant operations for the MongoDB deployment. To run, use the db.aggregate() method.
public
currentOp([Optional|bool $allUsers = Optional::Undefined ][, Optional|bool $idleConnections = Optional::Undefined ][, Optional|bool $idleCursors = Optional::Undefined ][, Optional|bool $idleSessions = Optional::Undefined ][, Optional|bool $localOps = Optional::Undefined ]) : static
Parameters
- $allUsers : Optional|bool = Optional::Undefined
- $idleConnections : Optional|bool = Optional::Undefined
- $idleCursors : Optional|bool = Optional::Undefined
- $idleSessions : Optional|bool = Optional::Undefined
- $localOps : Optional|bool = Optional::Undefined
Tags
Return values
staticdensify()
Creates new documents in a sequence of documents where certain values in a field are missing.
public
densify(string $field, Document|Serializable|array<string|int, mixed>|stdClass $range[, Optional|BSONArray|PackedArray|array<string|int, mixed> $partitionByFields = Optional::Undefined ]) : static
Parameters
- $field : string
-
The field to densify. The values of the specified field must either be all numeric values or all dates. Documents that do not contain the specified field continue through the pipeline unmodified. To specify a
in an embedded document or in an array, use dot notation. - $range : Document|Serializable|array<string|int, mixed>|stdClass
-
Specification for range based densification.
- $partitionByFields : Optional|BSONArray|PackedArray|array<string|int, mixed> = Optional::Undefined
-
The field(s) that will be used as the partition keys.
Tags
Return values
staticdocuments()
Returns literal documents from input values.
public
documents(BSONArray|PackedArray|ResolvesToArray|array<string|int, mixed>|string $documents) : static
Parameters
- $documents : BSONArray|PackedArray|ResolvesToArray|array<string|int, mixed>|string
-
$documents accepts any valid expression that resolves to an array of objects. This includes:
- system variables, such as $$NOW or $$SEARCH_META
- $let expressions
- variables in scope from $lookup expressions Expressions that do not resolve to a current document, like $myField or $$ROOT, will result in an error.
Tags
Return values
staticfacet()
Processes multiple aggregation pipelines within a single stage on the same set of input documents. Enables the creation of multi-faceted aggregations capable of characterizing data across multiple dimensions, or facets, in a single stage.
public
facet(BSONArray|PackedArray|Pipeline|array<string|int, mixed> ...$facet) : static
Parameters
Tags
Return values
staticfill()
Populates null and missing field values within documents.
public
fill(Document|Serializable|array<string|int, mixed>|stdClass $output[, Optional|Document|Serializable|array<string|int, mixed>|stdClass|string $partitionBy = Optional::Undefined ][, Optional|BSONArray|PackedArray|array<string|int, mixed> $partitionByFields = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $sortBy = Optional::Undefined ]) : static
Parameters
- $output : Document|Serializable|array<string|int, mixed>|stdClass
-
Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. The object name is the name of the field to fill. The object value specifies how the field is filled.
- $partitionBy : Optional|Document|Serializable|array<string|int, mixed>|stdClass|string = Optional::Undefined
-
Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. partitionBy and partitionByFields are mutually exclusive.
- $partitionByFields : Optional|BSONArray|PackedArray|array<string|int, mixed> = Optional::Undefined
-
Specifies an array of fields as the compound key to group the documents. In the $fill stage, each group of documents is known as a partition. If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. partitionBy and partitionByFields are mutually exclusive.
- $sortBy : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage.
Tags
Return values
staticgeoNear()
Returns an ordered stream of documents based on the proximity to a geospatial point. Incorporates the functionality of $match, $sort, and $limit for geospatial data. The output documents include an additional distance field and can include a location identifier field.
public
geoNear(Document|ResolvesToObject|Serializable|array<string|int, mixed>|stdClass|string $near[, Optional|string $distanceField = Optional::Undefined ][, Optional|Decimal128|Int64|float|int $distanceMultiplier = Optional::Undefined ][, Optional|string $includeLocs = Optional::Undefined ][, Optional|string $key = Optional::Undefined ][, Optional|Decimal128|Int64|float|int $maxDistance = Optional::Undefined ][, Optional|Decimal128|Int64|float|int $minDistance = Optional::Undefined ][, Optional|QueryInterface|array<string|int, mixed> $query = Optional::Undefined ][, Optional|bool $spherical = Optional::Undefined ]) : static
Parameters
- $near : Document|ResolvesToObject|Serializable|array<string|int, mixed>|stdClass|string
-
The point for which to find the closest documents.
- $distanceField : Optional|string = Optional::Undefined
-
The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation.
- $distanceMultiplier : Optional|Decimal128|Int64|float|int = Optional::Undefined
-
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.
- $includeLocs : Optional|string = Optional::Undefined
-
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 an embedded document, use dot notation.
- $key : Optional|string = Optional::Undefined
-
Specify the geospatial indexed field to use when calculating the distance.
- $maxDistance : Optional|Decimal128|Int64|float|int = Optional::Undefined
-
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.
- $minDistance : Optional|Decimal128|Int64|float|int = Optional::Undefined
-
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.
- $query : Optional|QueryInterface|array<string|int, mixed> = Optional::Undefined
-
Limits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. You cannot specify a $near predicate in the query field of the $geoNear stage.
- $spherical : Optional|bool = Optional::Undefined
-
Determines how MongoDB calculates the distance between two points:
- When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry.
- When false, MongoDB uses $near semantics: spherical geometry for 2dsphere indexes and planar geometry for 2d indexes. Default: false.
Tags
Return values
staticgetPipeline()
public
getPipeline() : Pipeline
Return values
PipelinegraphLookup()
Performs a recursive search on a collection. To each output document, adds a new array field that contains the traversal results of the recursive search for that document.
public
graphLookup(string $from, BSONArray|DateTimeInterface|ExpressionInterface|PackedArray|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string $startWith, string $connectFromField, string $connectToField, string $as[, Optional|int $maxDepth = Optional::Undefined ][, Optional|string $depthField = Optional::Undefined ][, Optional|QueryInterface|array<string|int, mixed> $restrictSearchWithMatch = Optional::Undefined ]) : static
Parameters
- $from : string
-
Target collection for the $graphLookup operation to search, recursively matching the connectFromField to the connectToField. The from collection must be in the same database as any other collections used in the operation. Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded.
- $startWith : BSONArray|DateTimeInterface|ExpressionInterface|PackedArray|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string
-
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.
- $connectFromField : string
-
Field name whose value $graphLookup uses to recursively match against the connectToField of other documents in the collection. If the value is an array, each element is individually followed through the traversal process.
- $connectToField : string
-
Field name in other documents against which to match the value of the field specified by the connectFromField parameter.
- $as : string
-
Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document.
- $maxDepth : Optional|int = Optional::Undefined
-
Non-negative integral number specifying the maximum recursion depth.
- $depthField : Optional|string = Optional::Undefined
-
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.
- $restrictSearchWithMatch : Optional|QueryInterface|array<string|int, mixed> = Optional::Undefined
-
A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax.
Tags
Return values
staticgroup()
Groups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group. Consumes all input documents and outputs one document per each distinct group. The output documents only contain the identifier field and, if specified, accumulated fields.
public
group(DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string $_id, AccumulatorInterface|Document|Serializable|array<string|int, mixed>|stdClass ...$field) : static
Parameters
- $_id : DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string
-
The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents.
- $field : AccumulatorInterface|Document|Serializable|array<string|int, mixed>|stdClass
-
Computed using the accumulator operators.
Tags
Return values
staticindexStats()
Returns statistics regarding the use of each index for the collection.
public
indexStats() : static
Tags
Return values
staticlimit()
Passes the first n documents unmodified to the pipeline where n is the specified limit. For each input document, outputs either one document (for the first n documents) or zero documents (after the first n documents).
public
limit(int $limit) : static
Parameters
- $limit : int
Tags
Return values
staticlistLocalSessions()
Lists all active sessions recently in use on the currently connected mongos or mongod instance. These sessions may have not yet propagated to the system.sessions collection.
public
listLocalSessions([Optional|BSONArray|PackedArray|array<string|int, mixed> $users = Optional::Undefined ][, Optional|bool $allUsers = Optional::Undefined ]) : static
Parameters
- $users : Optional|BSONArray|PackedArray|array<string|int, mixed> = Optional::Undefined
-
Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users.
- $allUsers : Optional|bool = Optional::Undefined
-
Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster.
Tags
Return values
staticlistSampledQueries()
Lists sampled queries for all collections or a specific collection.
public
listSampledQueries([Optional|string $namespace = Optional::Undefined ]) : static
Parameters
- $namespace : Optional|string = Optional::Undefined
Tags
Return values
staticlistSearchIndexes()
Returns information about existing Atlas Search indexes on a specified collection.
public
listSearchIndexes([Optional|string $id = Optional::Undefined ][, Optional|string $name = Optional::Undefined ]) : static
Parameters
- $id : Optional|string = Optional::Undefined
-
The id of the index to return information about.
- $name : Optional|string = Optional::Undefined
-
The name of the index to return information about.
Tags
Return values
staticlistSessions()
Lists all sessions that have been active long enough to propagate to the system.sessions collection.
public
listSessions([Optional|BSONArray|PackedArray|array<string|int, mixed> $users = Optional::Undefined ][, Optional|bool $allUsers = Optional::Undefined ]) : static
Parameters
- $users : Optional|BSONArray|PackedArray|array<string|int, mixed> = Optional::Undefined
-
Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users.
- $allUsers : Optional|bool = Optional::Undefined
-
Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster.
Tags
Return values
staticlookup()
Performs a left outer join to another collection in the same database to filter in documents from the "joined" collection for processing.
public
lookup(string $as[, Optional|string $from = Optional::Undefined ][, Optional|string $localField = Optional::Undefined ][, Optional|string $foreignField = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $let = Optional::Undefined ][, Optional|BSONArray|PackedArray|Pipeline|array<string|int, mixed> $pipeline = Optional::Undefined ]) : static
Parameters
- $as : string
-
Specifies the name of the new array field to add to the input documents. The new array field contains the matching documents from the from collection. If the specified name already exists in the input document, the existing field is overwritten.
- $from : Optional|string = Optional::Undefined
-
Specifies the collection in the same database to perform the join with. from is optional, you can use a $documents stage in a $lookup stage instead. For an example, see Use a $documents Stage in a $lookup Stage. Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded.
- $localField : Optional|string = Optional::Undefined
-
Specifies the field from the documents input to the $lookup stage. $lookup performs an equality match on the localField to the foreignField from the documents of the from collection. If an input document does not contain the localField, the $lookup treats the field as having a value of null for matching purposes.
- $foreignField : Optional|string = Optional::Undefined
-
Specifies the field from the documents in the from collection. $lookup performs an equality match on the foreignField to the localField from the input documents. If a document in the from collection does not contain the foreignField, the $lookup treats the value as null for matching purposes.
- $let : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
Specifies variables to use in the pipeline stages. Use the variable expressions to access the fields from the joined collection's documents that are input to the pipeline.
- $pipeline : Optional|BSONArray|PackedArray|Pipeline|array<string|int, mixed> = Optional::Undefined
-
Specifies the pipeline to run on the joined collection. The pipeline determines the resulting documents from the joined collection. To return all documents, specify an empty pipeline []. The pipeline cannot include the $out stage or the $merge stage. Starting in v6.0, the pipeline can contain the Atlas Search $search stage as the first stage inside the pipeline. The pipeline cannot directly access the joined document fields. Instead, define variables for the joined document fields using the let option and then reference the variables in the pipeline stages.
Tags
Return values
staticmatch()
Filters the document stream to allow only matching documents to pass unmodified into the next pipeline stage. $match uses standard MongoDB queries. For each input document, outputs either one document (a match) or zero documents (no match).
public
match(DateTimeInterface|QueryInterface|FieldQueryInterface|Type|stdClass|array<string|int, mixed>|bool|float|int|string|null ...$queries) : static
Parameters
- $queries : DateTimeInterface|QueryInterface|FieldQueryInterface|Type|stdClass|array<string|int, mixed>|bool|float|int|string|null
-
The query predicates to match
Tags
Return values
staticmerge()
Writes the resulting documents of the aggregation pipeline to a collection. The stage can incorporate (insert new documents, merge documents, replace documents, keep existing documents, fail the operation, process documents with a custom update pipeline) the results into an output collection. To use the $merge stage, it must be the last stage in the pipeline.
public
merge(Document|Serializable|array<string|int, mixed>|stdClass|string $into[, Optional|BSONArray|PackedArray|array<string|int, mixed>|string $on = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $let = Optional::Undefined ][, Optional|BSONArray|PackedArray|Pipeline|array<string|int, mixed>|string $whenMatched = Optional::Undefined ][, Optional|string $whenNotMatched = Optional::Undefined ]) : static
New in MongoDB 4.2.
Parameters
- $into : Document|Serializable|array<string|int, mixed>|stdClass|string
-
The output collection.
- $on : Optional|BSONArray|PackedArray|array<string|int, mixed>|string = Optional::Undefined
-
Field or fields that act as a unique identifier for a document. The identifier determines if a results document matches an existing document in the output collection.
- $let : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
Specifies variables for use in the whenMatched pipeline.
- $whenMatched : Optional|BSONArray|PackedArray|Pipeline|array<string|int, mixed>|string = Optional::Undefined
-
The behavior of $merge if a result document and an existing document in the collection have the same value for the specified on field(s).
- $whenNotMatched : Optional|string = Optional::Undefined
-
The behavior of $merge if a result document does not match an existing document in the out collection.
Tags
Return values
staticout()
Writes the resulting documents of the aggregation pipeline to a collection. To use the $out stage, it must be the last stage in the pipeline.
public
out(Document|Serializable|array<string|int, mixed>|stdClass|string $coll) : static
Parameters
- $coll : Document|Serializable|array<string|int, mixed>|stdClass|string
-
Target database name to write documents from $out to.
Tags
Return values
staticplanCacheStats()
Returns plan cache information for a collection.
public
planCacheStats() : static
Tags
Return values
staticproject()
Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document.
public
project(DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string ...$specification) : static
Parameters
- $specification : DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string
Tags
Return values
staticredact()
Reshapes each document in the stream by restricting the content for each document based on information stored in the documents themselves. Incorporates the functionality of $project and $match. Can be used to implement field level redaction. For each input document, outputs either one or zero documents.
public
redact(DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string $expression) : static
Parameters
- $expression : DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string
Tags
Return values
staticreplaceRoot()
Replaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the _id field. Specify a document embedded in the input document to promote the embedded document to the top level.
public
replaceRoot(Document|ResolvesToObject|Serializable|array<string|int, mixed>|stdClass|string $newRoot) : static
Parameters
- $newRoot : Document|ResolvesToObject|Serializable|array<string|int, mixed>|stdClass|string
Tags
Return values
staticreplaceWith()
Replaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the _id field. Specify a document embedded in the input document to promote the embedded document to the top level.
public
replaceWith(Document|ResolvesToObject|Serializable|array<string|int, mixed>|stdClass|string $expression) : static
Alias for $replaceRoot.
Parameters
- $expression : Document|ResolvesToObject|Serializable|array<string|int, mixed>|stdClass|string
Tags
Return values
staticsample()
Randomly selects the specified number of documents from its input.
public
sample(int $size) : static
Parameters
- $size : int
-
The number of documents to randomly select.
Tags
Return values
staticscoreFusion()
Combines multiple pipelines using relative score fusion to create hybrid search results.
public
scoreFusion(Document|Serializable|array<string|int, mixed>|stdClass $input[, bool $scoreDetails = false ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $combination = Optional::Undefined ]) : static
Parameters
- $input : Document|Serializable|array<string|int, mixed>|stdClass
-
An object with the following required fields:
- input.pipelines: Map from name to input pipeline. Each pipeline must be operating on the same collection. Minimum of one pipeline.
- input.normalization: Normalizes the score to the range 0 to 1 before combining the results. Value can be none, sigmoid or minMaxScaler.
- $scoreDetails : bool = false
-
Set to true to include detailed scoring information.
- $combination : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
An object with the following optional fields:
- combination.weights: Map from pipeline name to numbers (non-negative). If unspecified, default weight is 1 for each pipeline.
- combination.method: Specifies method for combining scores. Value can be avg or expression. Default is avg.
- combination.expression: This is the custom expression that is used when combination.method is set to expression.
Tags
Return values
staticsearch()
Performs a full-text search of the field or fields in an Atlas collection.
public
search(Document|SearchOperatorInterface|Serializable|array<string|int, mixed>|stdClass $operator[, Optional|string $index = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $highlight = Optional::Undefined ][, Optional|bool $concurrent = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $count = Optional::Undefined ][, Optional|string $searchAfter = Optional::Undefined ][, Optional|string $searchBefore = Optional::Undefined ][, Optional|bool $scoreDetails = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $sort = Optional::Undefined ][, Optional|bool $returnStoredSource = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $tracking = Optional::Undefined ]) : static
NOTE: $search is only available for MongoDB Atlas clusters, and is not available for self-managed deployments.
Parameters
- $operator : Document|SearchOperatorInterface|Serializable|array<string|int, mixed>|stdClass
-
Operator to search with. You can provide a specific operator or use the compound operator to run a compound query with multiple operators.
- $index : Optional|string = Optional::Undefined
-
Name of the Atlas Search index to use. If omitted, defaults to "default".
- $highlight : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
Specifies the highlighting options for displaying search terms in their original context.
- $concurrent : Optional|bool = Optional::Undefined
-
Parallelize search across segments on dedicated search nodes. If you don't have separate search nodes on your cluster, Atlas Search ignores this flag. If omitted, defaults to false.
- $count : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
Document that specifies the count options for retrieving a count of the results.
- $searchAfter : Optional|string = Optional::Undefined
-
Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point.
- $searchBefore : Optional|string = Optional::Undefined
-
Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point.
- $scoreDetails : Optional|bool = Optional::Undefined
-
Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false.
- $sort : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
Document that specifies the fields to sort the Atlas Search results by in ascending or descending order.
- $returnStoredSource : Optional|bool = Optional::Undefined
-
Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search.
- $tracking : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
Document that specifies the tracking option to retrieve analytics information on the search terms.
Tags
Return values
staticsearchMeta()
Returns different types of metadata result documents for the Atlas Search query against an Atlas collection.
public
searchMeta(Document|SearchOperatorInterface|Serializable|array<string|int, mixed>|stdClass $operator[, Optional|string $index = Optional::Undefined ][, Optional|Document|Serializable|array<string|int, mixed>|stdClass $count = Optional::Undefined ]) : static
NOTE: $searchMeta is only available for MongoDB Atlas clusters running MongoDB v4.4.9 or higher, and is not available for self-managed deployments.
Parameters
- $operator : Document|SearchOperatorInterface|Serializable|array<string|int, mixed>|stdClass
-
Operator to search with. You can provide a specific operator or use the compound operator to run a compound query with multiple operators.
- $index : Optional|string = Optional::Undefined
-
Name of the Atlas Search index to use. If omitted, defaults to default.
- $count : Optional|Document|Serializable|array<string|int, mixed>|stdClass = Optional::Undefined
-
Document that specifies the count options for retrieving a count of the results.
Tags
Return values
staticset()
Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields.
public
set(DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string ...$field) : static
Alias for $addFields.
Parameters
- $field : DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string
Tags
Return values
staticsetWindowFields()
Groups documents into windows and applies one or more operators to the documents in each window.
public
setWindowFields(Document|Serializable|array<string|int, mixed>|stdClass $sortBy, Document|Serializable|array<string|int, mixed>|stdClass $output[, Optional|DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string $partitionBy = Optional::Undefined ]) : static
New in MongoDB 5.0.
Parameters
- $sortBy : Document|Serializable|array<string|int, mixed>|stdClass
-
Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting.
- $output : Document|Serializable|array<string|int, mixed>|stdClass
-
Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. A field can contain dots to specify embedded document fields and array fields. The semantics for the embedded document dotted notation in the $setWindowFields stage are the same as the $addFields and $set stages.
- $partitionBy : Optional|DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string = Optional::Undefined
-
Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection.
Tags
Return values
staticshardedDataDistribution()
Provides data and size distribution information on sharded collections.
public
shardedDataDistribution() : static
New in MongoDB 6.0.3.
Tags
Return values
staticskip()
Skips the first n documents where n is the specified skip number and passes the remaining documents unmodified to the pipeline. For each input document, outputs either zero documents (for the first n documents) or one document (if after the first n documents).
public
skip(int $skip) : static
Parameters
- $skip : int
Tags
Return values
staticsort()
Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document.
public
sort(DateTimeInterface|ExpressionInterface|Sort|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string ...$sort) : static
Parameters
- $sort : DateTimeInterface|ExpressionInterface|Sort|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string
Tags
Return values
staticsortByCount()
Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.
public
sortByCount(DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string $expression) : static
Parameters
- $expression : DateTimeInterface|ExpressionInterface|Type|array<string|int, mixed>|bool|float|int|null|stdClass|string
Tags
Return values
staticunionWith()
Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set.
public
unionWith(string $coll[, Optional|BSONArray|PackedArray|Pipeline|array<string|int, mixed> $pipeline = Optional::Undefined ]) : static
New in MongoDB 4.4.
Parameters
- $coll : string
-
The collection or view whose pipeline results you wish to include in the result set.
- $pipeline : Optional|BSONArray|PackedArray|Pipeline|array<string|int, mixed> = Optional::Undefined
-
An aggregation pipeline to apply to the specified coll. The pipeline cannot include the $out and $merge stages. Starting in v6.0, the pipeline can contain the Atlas Search $search stage as the first stage inside the pipeline.
Tags
Return values
staticunset()
Removes or excludes fields from documents.
public
unset(FieldPath|string ...$field) : static
Alias for $project stage that removes or excludes fields.
Parameters
- $field : FieldPath|string
Tags
Return values
staticunwind()
Deconstructs an array field from the input documents to output a document for each element. Each output document replaces the array with an element value. For each input document, outputs n documents where n is the number of array elements and can be zero for an empty array.
public
unwind(ArrayFieldPath|string $path[, Optional|string $includeArrayIndex = Optional::Undefined ][, Optional|bool $preserveNullAndEmptyArrays = Optional::Undefined ]) : static
Parameters
- $path : ArrayFieldPath|string
-
Field path to an array field.
- $includeArrayIndex : Optional|string = Optional::Undefined
-
The name of a new field to hold the array index of the element. The name cannot start with a dollar sign $.
- $preserveNullAndEmptyArrays : Optional|bool = Optional::Undefined
-
If true, if the path is null, missing, or an empty array, $unwind outputs the document. If false, if path is null, missing, or an empty array, $unwind does not output a document. The default value is false.
Tags
Return values
staticvectorSearch()
The $vectorSearch stage performs an ANN or ENN search on a vector in the specified field.
public
vectorSearch(string $index, int $limit, string $path, BSONArray|PackedArray|array<string|int, mixed> $queryVector[, Optional|bool $exact = Optional::Undefined ][, Optional|QueryInterface|array<string|int, mixed> $filter = Optional::Undefined ][, Optional|int $numCandidates = Optional::Undefined ]) : static
Parameters
- $index : string
-
Name of the Atlas Vector Search index to use.
- $limit : int
-
Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates.
- $path : string
-
Indexed vector type field to search.
- $queryVector : BSONArray|PackedArray|array<string|int, mixed>
-
Array of numbers that represent the query vector. The number type must match the indexed field value type.
- $exact : Optional|bool = Optional::Undefined
-
This is required if numCandidates is omitted. false to run ANN search. true to run ENN search.
- $filter : Optional|QueryInterface|array<string|int, mixed> = Optional::Undefined
-
Any match query that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter.
- $numCandidates : Optional|int = Optional::Undefined
-
This field is required if exact is false or omitted. Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return (limit).