class Expr (View source)

Query expression builder for ODM.

Methods

__construct(DocumentManager $dm)

No description

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

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

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

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

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

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

addToSet(mixed|Expr $valueOrExpression)

Append one or more values to the current array field only if they do not already exist in the array.

all(array $values)

Specify $all criteria for the current field.

bit(string $operator, int $value)

Apply a bitwise operation on the current field

bitAnd(int $value)

Apply a bitwise and operation on the current field.

bitOr(int $value)

Apply a bitwise or operation on the current field.

bitsAllClear(int|array|Binary $value)

Matches documents where all of the bit positions given by the query are clear.

bitsAllSet(int|array|Binary $value)

Matches documents where all of the bit positions given by the query are set.

bitsAnyClear(int|array|Binary $value)

Matches documents where any of the bit positions given by the query are clear.

bitsAnySet(int|array|Binary $value)

Matches documents where any of the bit positions given by the query are set.

bitXor(int $value)

Apply a bitwise xor operation on the current field.

caseSensitive(bool $caseSensitive)

A boolean flag to enable or disable case sensitive search for $text criteria.

comment(string $comment)

Associates a comment to any expression taking a query predicate.

currentDate(string $type = 'date')

Sets the value of the current field to the current date, either as a date or a timestamp.

diacriticSensitive(bool $diacriticSensitive)

A boolean flag to enable or disable diacritic sensitive search for $text criteria.

each(array $values)

Add $each criteria to the expression for a $push operation.

elemMatch(array|Expr $expression)

Specify $elemMatch criteria for the current field.

equals(mixed $value)

Specify an equality match for the current field.

$this
exists(bool $bool)

Specify $exists criteria for the current field.

field(string $field)

Set the current field for building the expression.

geoIntersects(array|Geometry $geometry)

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

geoWithin(array|Geometry $geometry)

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

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

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

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

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

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

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

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

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

getCurrentField()

Return the current field.

getNewObj()

Gets prepared newObj part of expression.

getQuery()

Gets prepared query part of expression.

gt(mixed $value)

Specify $gt criteria for the current field.

gte(mixed $value)

Specify $gte criteria for the current field.

in(array $values)

Specify $in criteria for the current field.

inc(float|int $value)

Increment the current field.

includesReferenceTo(object $document)

Checks that the current field includes a reference to the supplied document.

language(string $language)

Set the $language option for $text criteria.

lt(mixed $value)

Specify $lt criteria for the current field.

lte(mixed $value)

Specify $lte criteria for the current field.

max(mixed $value)

Updates the value of the field to a specified value if the specified value is greater than the current value of the field.

min(mixed $value)

Updates the value of the field to a specified value if the specified value is less than the current value of the field.

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

Specify $mod criteria for the current field.

mul(float|int $value)

Multiply the current field.

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

Add $near criteria to the expression.

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

Add $nearSphere criteria to the expression.

not(array|Expr $expression)

Negates an expression for the current field.

notEqual(mixed $value)

Specify $ne criteria for the current field.

notIn(array $values)

Specify $nin criteria for the current field.

operator(string $operator, $value)

Defines an operator and value on the expression.

popFirst()

Remove the first element from the current array field.

popLast()

Remove the last element from the current array field.

position(int $position)

Add $position criteria to the expression for a $push operation.

pull(mixed|Expr $valueOrExpression)

Remove all elements matching the given value or expression from the current array field.

pullAll(array $values)

Remove all elements matching any of the given values from the current array field.

push(mixed|Expr $valueOrExpression)

Append one or more values to the current array field.

range(mixed $start, mixed $end)

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

references(object $document)

Checks that the value of the current field is a reference to the supplied document.

rename(string $name)

Rename the current field.

set($value, bool $atomic = true)

Set the current field to a value.

setClassMetadata(ClassMetadata $class)

Sets ClassMetadata for document being queried.

setNewObj(array $newObj)

Set the "new object".

setOnInsert(mixed $value)

Set the current field to the value if the document is inserted in an upsert operation.

setQuery(array $query)

Set the query criteria.

size(int $size)

Specify $size criteria for the current field.

slice(int $slice)

Add $slice criteria to the expression for a $push operation.

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

Add $sort criteria to the expression for a $push operation.

text(string $search)

Specify $text criteria for the current query.

type(int|string $type)

Specify $type criteria for the current field.

unsetField()

Unset the current field.

where(string|Javascript $javascript)

Specify a JavaScript expression to use for matching documents.

Details

__construct(DocumentManager $dm)

Parameters

DocumentManager $dm

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

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

Parameters

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

See also

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

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

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

Parameters

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

See also

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

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

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

Parameters

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

See also

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

addToSet(mixed|Expr $valueOrExpression)

Append one or more values to the current array field only if they do not already exist in the array.

If the field does not exist, it will be set to an array containing the unique value(s) in the argument. If the field is not an array, the query will yield an error.

Multiple values may be specified by provided an Expr object and using {@link Expr::each()}.

all(array $values)

Specify $all criteria for the current field.

protected bit(string $operator, int $value)

Apply a bitwise operation on the current field

Parameters

string $operator
int $value

See also

http://docs.mongodb.org/manual/reference/operator/update/bit/

bitAnd(int $value)

Apply a bitwise and operation on the current field.

bitOr(int $value)

Apply a bitwise or operation on the current field.

bitsAllClear(int|array|Binary $value)

Matches documents where all of the bit positions given by the query are clear.

bitsAllSet(int|array|Binary $value)

Matches documents where all of the bit positions given by the query are set.

bitsAnyClear(int|array|Binary $value)

Matches documents where any of the bit positions given by the query are clear.

bitsAnySet(int|array|Binary $value)

Matches documents where any of the bit positions given by the query are set.

bitXor(int $value)

Apply a bitwise xor operation on the current field.

caseSensitive(bool $caseSensitive)

A boolean flag to enable or disable case sensitive search for $text criteria.

This method must be called after text().

Parameters

bool $caseSensitive

Exceptions

BadMethodCallException If the query does not already have $text criteria.

See also

Builder::caseSensitive
http://docs.mongodb.org/manual/reference/operator/text/

comment(string $comment)

Associates a comment to any expression taking a query predicate.

currentDate(string $type = 'date')

Sets the value of the current field to the current date, either as a date or a timestamp.

Parameters

string $type

Exceptions

InvalidArgumentException If an invalid type is given.

See also

Builder::currentDate
http://docs.mongodb.org/manual/reference/operator/update/currentDate/

diacriticSensitive(bool $diacriticSensitive)

A boolean flag to enable or disable diacritic sensitive search for $text criteria.

This method must be called after text().

Parameters

bool $diacriticSensitive

Exceptions

BadMethodCallException If the query does not already have $text criteria.

See also

Builder::diacriticSensitive
http://docs.mongodb.org/manual/reference/operator/text/

each(array $values)

Add $each criteria to the expression for a $push operation.

elemMatch(array|Expr $expression)

Specify $elemMatch criteria for the current field.

equals(mixed $value)

Specify an equality match for the current field.

Parameters

mixed $value

See also

Builder::equals

$this exists(bool $bool)

Specify $exists criteria for the current field.

Parameters

bool $bool

Return Value

$this

See also

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

field(string $field)

Set the current field for building the expression.

Parameters

string $field

See also

Builder::field

geoIntersects(array|Geometry $geometry)

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

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

geoWithin(array|Geometry $geometry)

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

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

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

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

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

See also

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

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

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

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

See also

Builider::geoWithinCenter()
http://docs.mongodb.org/manual/reference/operator/center/

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

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

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

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

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

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

Exceptions

InvalidArgumentException If less than three points are given.

See also

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

getCurrentField()

Return the current field.

getNewObj()

Gets prepared newObj part of expression.

getQuery()

Gets prepared query part of expression.

gt(mixed $value)

Specify $gt criteria for the current field.

gte(mixed $value)

Specify $gte criteria for the current field.

in(array $values)

Specify $in criteria for the current field.

inc(float|int $value)

Increment the current field.

If the field does not exist, it will be set to this value.

includesReferenceTo(object $document)

Checks that the current field includes a reference to the supplied document.

Parameters

object $document

language(string $language)

Set the $language option for $text criteria.

This method must be called after text().

Parameters

string $language

Exceptions

BadMethodCallException If the query does not already have $text criteria.

See also

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

lt(mixed $value)

Specify $lt criteria for the current field.

lte(mixed $value)

Specify $lte criteria for the current field.

max(mixed $value)

Updates the value of the field to a specified value if the specified value is greater than the current value of the field.

min(mixed $value)

Updates the value of the field to a specified value if the specified value is less than the current value of the field.

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

Specify $mod criteria for the current field.

Parameters

float|int $divisor
float|int $remainder

See also

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

mul(float|int $value)

Multiply the current field.

If the field does not exist, it will be set to 0.

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

Add $near criteria to the expression.

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.

Parameters

float|array|Point $x
float $y

See also

Builder::near
http://docs.mongodb.org/manual/reference/operator/near/

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

Add $nearSphere criteria to the expression.

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.

not(array|Expr $expression)

Negates an expression for the current field.

notEqual(mixed $value)

Specify $ne criteria for the current field.

notIn(array $values)

Specify $nin criteria for the current field.

operator(string $operator, $value)

Defines an operator and value on the expression.

If there is a current field, the operator will be set on it; otherwise, the operator is set at the top level of the query.

Parameters

string $operator
$value

popFirst()

Remove the first element from the current array field.

popLast()

Remove the last element from the current array field.

position(int $position)

Add $position criteria to the expression for a $push operation.

This is useful in conjunction with {@link Expr::each()} for a {@link Expr::push()} operation.

pull(mixed|Expr $valueOrExpression)

Remove all elements matching the given value or expression from the current array field.

Parameters

mixed|Expr $valueOrExpression

See also

Builder::pull
http://docs.mongodb.org/manual/reference/operator/pull/

pullAll(array $values)

Remove all elements matching any of the given values from the current array field.

push(mixed|Expr $valueOrExpression)

Append one or more values to the current array field.

If the field does not exist, it will be set to an array containing the value(s) in the argument. If the field is not an array, the query will yield an error.

Multiple values may be specified by providing an Expr object and using {@link Expr::each()}. {@link Expr::slice()} and {@link Expr::sort()} may also be used to limit and order array elements, respectively.

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

See also

Builder::range

references(object $document)

Checks that the value of the current field is a reference to the supplied document.

Parameters

object $document

rename(string $name)

Rename the current field.

set($value, bool $atomic = true)

Set the current field to a value.

This is only relevant for insert, update, or findAndUpdate queries. For update and findAndUpdate queries, the $atomic parameter will determine whether or not a $set operator is used.

setClassMetadata(ClassMetadata $class)

Sets ClassMetadata for document being queried.

Parameters

ClassMetadata $class

setNewObj(array $newObj)

Set the "new object".

Parameters

array $newObj

See also

Builder::setNewObj

setOnInsert(mixed $value)

Set the current field to the value if the document is inserted in an upsert operation.

If an update operation with upsert: true results in an insert of a document, then $setOnInsert assigns the specified values to the fields in the document. If the update operation does not result in an insert, $setOnInsert does nothing.

setQuery(array $query)

Set the query criteria.

Parameters

array $query

See also

Builder::setQueryArray

size(int $size)

Specify $size criteria for the current field.

slice(int $slice)

Add $slice criteria to the expression for a $push operation.

This is useful in conjunction with {@link Expr::each()} for a {@link Expr::push()} operation. {@link Builder::selectSlice()} should be used for specifying $slice for a query projection.

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

Add $sort criteria to the expression for a $push operation.

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

This is useful in conjunction with {@link Expr::each()} for a {@link Expr::push()} operation. {@link Builder::sort()} should be used to sort the results of a query.

Parameters

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

See also

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

text(string $search)

Specify $text criteria for the current query.

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

type(int|string $type)

Specify $type criteria for the current field.

unsetField()

Unset the current field.

The field will be removed from the document (not set to null).

where(string|Javascript $javascript)

Specify a JavaScript expression to use for matching documents.

Parameters

string|Javascript $javascript

See also

Builder::where
http://docs.mongodb.org/manual/reference/operator/where/