class Builder (View source)

Query builder for ODM.

Properties

protected string $currentField The current field we are operating on.

Methods

__construct(DocumentManager $dm, $documentName = null)

Construct a Builder

__clone()

No description

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

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

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

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

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

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

$this
addToSet(mixed|Expr $valueOrExpression)

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

$this
all(array $values)

Specify $all criteria for the current field.

$this
bitAnd(int $value)

Apply a bitwise and operation on the current field.

$this
bitOr(int $value)

Apply a bitwise or operation on the current field.

$this
bitsAllClear(int|array|Binary $value)

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

$this
bitsAllSet(int|array|Binary $value)

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

$this
bitsAnyClear(int|array|Binary $value)

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

$this
bitsAnySet(int|array|Binary $value)

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

$this
bitXor(int $value)

Apply a bitwise xor operation on the current field.

$this
caseSensitive(bool $caseSensitive)

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

$this
comment(string $comment)

Associates a comment to any expression taking a query predicate.

$this
count()

Change the query type to count.

$this
currentDate(string $type = 'date')

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

mixed
debug(string $name = null)

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

$this
diacriticSensitive(bool $diacriticSensitive)

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

$this
distinct(string $field)

Change the query type to a distinct command.

$this
eagerCursor(bool $bool = true)

Set whether the query should return its result as an EagerCursor.

$this
elemMatch(array|Expr $expression)

Specify $elemMatch criteria for the current field.

$this
equals(mixed $value)

Specify an equality match for the current field.

$this
exclude($fieldName = null)

Set one or more fields to be excluded from the query projection.

$this
exists(bool $bool)

Specify $exists criteria for the current field.

expr()

Create a new Expr instance that can be used as an expression with the Builder

$this
field(string $field)

Set the current field to operate on.

$this
finalize(string|Javascript $finalize)

Set the "finalize" option for a mapReduce or group command.

$this
find(string $documentName = null)

Change the query type to find and optionally set and change the class being queried.

$this
findAndRemove(string $documentName = null)

No description

$this
findAndUpdate(string $documentName = null)

No description

$this
geoIntersects(array|Geometry $geometry)

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

$this
geoWithin(array|Geometry $geometry)

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

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

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

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

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

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

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

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

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

array
getNewObj()

Return the expression's "new object".

getQuery(array $options = [])

Gets the Query executable.

array
getQueryArray()

Return the expression's query criteria.

int
getType()

Get the type of this query.

$this
gt(mixed $value)

Specify $gt criteria for the current field.

$this
gte(mixed $value)

Specify $gte criteria for the current field.

$this
hint(array|string $index)

Set the index hint for the query.

$this
hydrate(bool $bool = true)

No description

$this
immortal(bool $bool = true)

Set the immortal cursor flag.

$this
in(array $values)

Specify $in criteria for the current field.

$this
inc(float|int $value)

Increment the current field.

$this
includesReferenceTo(object $document)

No description

$this
insert(string $documentName = null)

No description

$this
language(string $language)

Set the $language option for $text criteria.

$this
limit(int $limit)

Set the limit for the query.

$this
lt(mixed $value)

Specify $lt criteria for the current field.

$this
lte(mixed $value)

Specify $lte criteria for the current field.

$this
map(string|Javascript $map)

Change the query type to a mapReduce command.

$this
mapReduce(string|Javascript $map, string|Javascript $reduce, array|string $out = ['inline' => true], array $options = [])

Change the query type to a mapReduce command.

$this
mapReduceOptions(array $options)

Set additional options for a mapReduce command.

$this
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.

$this
maxTimeMS(int $ms)

Specifies a cumulative time limit in milliseconds for processing operations on a cursor.

$this
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.

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

Specify $mod criteria for the current field.

$this
mul(float|int $value)

Multiply the current field.

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

Add $near criteria to the query.

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

Add $nearSphere criteria to the query.

$this
not(array|Expr $expression)

Negates an expression for the current field.

$this
notEqual(mixed $value)

Specify $ne criteria for the current field.

$this
notIn(array $values)

Specify $nin criteria for the current field.

$this
out(array|string $out)

Set the "out" option for a mapReduce command.

$this
popFirst()

Remove the first element from the current array field.

$this
popLast()

Remove the last element from the current array field.

$this
prime(bool|callable $primer = true)

Use a primer to eagerly load all references in the current field.

$this
pull(mixed|Expr $valueOrExpression)

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

$this
pullAll(array $values)

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

$this
push(mixed|Expr $valueOrExpression)

Append one or more values to the current array field.

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

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

$this
readOnly(bool $bool = true)

No description

$this
reduce(string|Javascript $reduce)

Set the "reduce" option for a mapReduce or group command.

$this
references(object $document)

No description

$this
refresh(bool $bool = true)

No description

$this
remove(string $documentName = null)

No description

$this
rename(string $name)

Rename the current field.

$this
returnNew(bool $bool = true)

No description

$this
select($fieldName = null)

Set one or more fields to be included in the query projection.

$this
selectElemMatch(string $fieldName, array|Expr $expression)

Select only matching embedded documents in an array field for the query projection.

$this
selectMeta(string $fieldName, string $metaDataKeyword)

Select a metadata field for the query projection.

$this
selectSlice(string $fieldName, int $countOrSkip, int $limit = null)

Select a slice of an array field for the query projection.

$this
set(mixed $value, bool $atomic = true)

Set the current field to a value.

$this
setNewObj(array $newObj)

Set the expression's "new object".

$this
setOnInsert(mixed $value)

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

$this
setReadPreference(ReadPreference $readPreference)

Set the read preference for the query.

$this
setQueryArray(array $query)

Set the expression's query criteria.

$this
size(int $size)

Specify $size criteria for the current field.

$this
skip(int $skip)

Set the skip for the query cursor.

$this
snapshot(bool $bool = true)

Set the snapshot cursor flag.

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

Set one or more field/order pairs on which to sort the query.

$this
sortMeta(string $fieldName, string $metaDataKeyword)

Specify a projected metadata field on which to sort the query.

$this
text(string $search)

Specify $text criteria for the current field.

$this
type(int $type)

Specify $type criteria for the current field.

$this
unsetField()

Unset the current field.

$this
updateOne(string $documentName = null)

No description

$this
updateMany(string $documentName = null)

No description

$this
upsert(bool $bool = true)

Set the "upsert" option for an update or findAndUpdate query.

$this
where(string|Javascript $javascript)

Specify a JavaScript expression to use for matching documents.

Details

__construct(DocumentManager $dm, $documentName = null)

Construct a Builder

Parameters

DocumentManager $dm
$documentName

__clone()

$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::expr()} 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::expr()} 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::expr()} method.

Parameters

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

Return Value

$this

See also

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

$this 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()}.

$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/

$this bitAnd(int $value)

Apply a bitwise and operation on the current field.

Parameters

int $value

Return Value

$this

See also

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

$this bitOr(int $value)

Apply a bitwise or operation on the current field.

Parameters

int $value

Return Value

$this

See also

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

$this bitsAllClear(int|array|Binary $value)

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

Parameters

int|array|Binary $value

Return Value

$this

See also

Expr::bitsAllClear
https://docs.mongodb.org/manual/reference/operator/query/bitsAllClear/

$this bitsAllSet(int|array|Binary $value)

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

Parameters

int|array|Binary $value

Return Value

$this

See also

Expr::bitsAllSet
https://docs.mongodb.org/manual/reference/operator/query/bitsAllSet/

$this bitsAnyClear(int|array|Binary $value)

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

Parameters

int|array|Binary $value

Return Value

$this

See also

Expr::bitsAnyClear
https://docs.mongodb.org/manual/reference/operator/query/bitsAnyClear/

$this bitsAnySet(int|array|Binary $value)

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

Parameters

int|array|Binary $value

Return Value

$this

See also

Expr::bitsAnySet
https://docs.mongodb.org/manual/reference/operator/query/bitsAnySet/

$this bitXor(int $value)

Apply a bitwise xor operation on the current field.

Parameters

int $value

Return Value

$this

See also

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

$this 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

Return Value

$this

Exceptions

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

See also

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

$this comment(string $comment)

Associates a comment to any expression taking a query predicate.

Parameters

string $comment

Return Value

$this

See also

Expr::comment
http://docs.mongodb.org/manual/reference/operator/query/comment/

$this count()

Change the query type to count.

Return Value

$this

$this 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

Return Value

$this

See also

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

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 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

Return Value

$this

Exceptions

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

See also

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

$this distinct(string $field)

Change the query type to a distinct command.

Parameters

string $field

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/command/distinct/

$this eagerCursor(bool $bool = true)

Set whether the query should return its result as an EagerCursor.

Parameters

bool $bool

Return Value

$this

$this elemMatch(array|Expr $expression)

Specify $elemMatch criteria for the current field.

You can create a new expression using the {@link Builder::expr()} 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 exclude($fieldName = null)

Set one or more fields to be excluded from the query projection.

If fields have been selected for inclusion, only the "_id" field may be excluded.

Parameters

$fieldName

Return Value

$this

$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 as an expression with the Builder

Return Value

Expr $expr

$this field(string $field)

Set the current field to operate on.

Parameters

string $field

Return Value

$this

$this finalize(string|Javascript $finalize)

Set the "finalize" option for a mapReduce or group command.

Parameters

string|Javascript $finalize

Return Value

$this

Exceptions

BadMethodCallException If the query is not a mapReduce or group command.

$this find(string $documentName = null)

Change the query type to find and optionally set and change the class being queried.

Parameters

string $documentName

Return Value

$this

$this findAndRemove(string $documentName = null)

Parameters

string $documentName

Return Value

$this

$this findAndUpdate(string $documentName = null)

Parameters

string $documentName

Return Value

$this

$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(array|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

array|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/

array getNewObj()

Return the expression's "new object".

Return Value

array

See also

Expr::getNewObj

Query getQuery(array $options = [])

Gets the Query executable.

Parameters

array $options

Return Value

Query $query

array getQueryArray()

Return the expression's query criteria.

Return Value

array

See also

Expr::getQuery

int getType()

Get the type of this query.

Return Value

int $type

$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 hint(array|string $index)

Set the index hint for the query.

Parameters

array|string $index

Return Value

$this

$this hydrate(bool $bool = true)

Parameters

bool $bool

Return Value

$this

$this immortal(bool $bool = true)

Set the immortal cursor flag.

Parameters

bool $bool

Return Value

$this

$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 inc(float|int $value)

Increment the current field.

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

Parameters

float|int $value

Return Value

$this

See also

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

$this includesReferenceTo(object $document)

Parameters

object $document

Return Value

$this

$this insert(string $documentName = null)

Parameters

string $documentName

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

Set the limit for the query.

This is only relevant for find queries and geoNear and mapReduce commands.

Parameters

int $limit

Return Value

$this

See also

Query::prepareCursor()

$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 map(string|Javascript $map)

Change the query type to a mapReduce command.

The "reduce" option is not specified when calling this method; it must be set with the {@link Builder::reduce()} method.

The "out" option defaults to inline, like {@link Builder::mapReduce()}.

Parameters

string|Javascript $map

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/command/mapReduce/

$this mapReduce(string|Javascript $map, string|Javascript $reduce, array|string $out = ['inline' => true], array $options = [])

Change the query type to a mapReduce command.

Parameters

string|Javascript $map
string|Javascript $reduce
array|string $out
array $options

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/command/mapReduce/

$this mapReduceOptions(array $options)

Set additional options for a mapReduce command.

Parameters

array $options

Return Value

$this

Exceptions

BadMethodCallException If the query is not a mapReduce command.

$this 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.

Parameters

mixed $value

Return Value

$this

See also

Expr::max
http://docs.mongodb.org/manual/reference/operator/update/max/

$this maxTimeMS(int $ms)

Specifies a cumulative time limit in milliseconds for processing operations on a cursor.

Parameters

int $ms

Return Value

$this

$this 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.

Parameters

mixed $value

Return Value

$this

See also

Expr::min
http://docs.mongodb.org/manual/reference/operator/update/min/

$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 mul(float|int $value)

Multiply the current field.

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

Parameters

float|int $value

Return Value

$this

See also

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

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

Add $near criteria to the query.

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

Return Value

$this

See also

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

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

Add $nearSphere criteria to the query.

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

Return Value

$this

See also

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

$this not(array|Expr $expression)

Negates an expression for the current field.

You can create a new expression using the {@link Builder::expr()} 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 out(array|string $out)

Set the "out" option for a mapReduce command.

Parameters

array|string $out

Return Value

$this

Exceptions

BadMethodCallException If the query is not a mapReduce command.

$this popFirst()

Remove the first element from the current array field.

$this popLast()

Remove the last element from the current array field.

$this prime(bool|callable $primer = true)

Use a primer to eagerly load all references in the current field.

If $primer is true or a callable is provided, referenced documents for this field will loaded into UnitOfWork immediately after the query is executed. This will avoid multiple queries due to lazy initialization of Proxy objects.

If $primer is false, no priming will take place. That is also the default behavior.

If a custom callable is used, its signature should conform to the default Closure defined in {@link ReferencePrimer::__construct()}.

Parameters

bool|callable $primer

Return Value

$this

Exceptions

InvalidArgumentException If $primer is not boolean or callable.

$this pull(mixed|Expr $valueOrExpression)

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

Parameters

mixed|Expr $valueOrExpression

Return Value

$this

See also

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

$this pullAll(array $values)

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

Parameters

array $values

Return Value

$this

See also

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

$this 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.

$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 readOnly(bool $bool = true)

Parameters

bool $bool

Return Value

$this

$this reduce(string|Javascript $reduce)

Set the "reduce" option for a mapReduce or group command.

Parameters

string|Javascript $reduce

Return Value

$this

Exceptions

BadMethodCallException If the query is not a mapReduce or group command.

$this references(object $document)

Parameters

object $document

Return Value

$this

$this refresh(bool $bool = true)

Parameters

bool $bool

Return Value

$this

$this remove(string $documentName = null)

Parameters

string $documentName

Return Value

$this

$this rename(string $name)

Rename the current field.

Parameters

string $name

Return Value

$this

See also

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

$this returnNew(bool $bool = true)

Parameters

bool $bool

Return Value

$this

$this select($fieldName = null)

Set one or more fields to be included in the query projection.

Parameters

$fieldName

Return Value

$this

$this selectElemMatch(string $fieldName, array|Expr $expression)

Select only matching embedded documents in an array field for the query projection.

Parameters

string $fieldName
array|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/projection/elemMatch/

$this selectMeta(string $fieldName, string $metaDataKeyword)

Select a metadata field for the query projection.

Parameters

string $fieldName
string $metaDataKeyword

Return Value

$this

See also

http://docs.mongodb.org/master/reference/operator/projection/meta/

$this selectSlice(string $fieldName, int $countOrSkip, int $limit = null)

Select a slice of an array field for the query projection.

The $countOrSkip parameter has two very different meanings, depending on whether or not $limit is provided. See the MongoDB documentation for more information.

Parameters

string $fieldName
int $countOrSkip Count parameter, or skip if limit is specified
int $limit Limit parameter used in conjunction with skip

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/projection/slice/

$this set(mixed $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.

Parameters

mixed $value
bool $atomic

Return Value

$this

See also

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

$this setNewObj(array $newObj)

Set the expression's "new object".

Parameters

array $newObj

Return Value

$this

See also

Expr::setNewObj

$this 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.

$this setReadPreference(ReadPreference $readPreference)

Set the read preference for the query.

This is only relevant for read-only queries and commands.

Parameters

ReadPreference $readPreference

Return Value

$this

See also

http://docs.mongodb.org/manual/core/read-preference/

$this setQueryArray(array $query)

Set the expression's query criteria.

Parameters

array $query

Return Value

$this

See also

Expr::setQuery

$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 skip(int $skip)

Set the skip for the query cursor.

This is only relevant for find queries, or mapReduce queries that store results in an output collecton and return a cursor.

Parameters

int $skip

Return Value

$this

See also

Query::prepareCursor()

$this snapshot(bool $bool = true)

Set the snapshot cursor flag.

Parameters

bool $bool

Return Value

$this

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

Set one or more field/order pairs on which to sort the query.

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

$this

$this sortMeta(string $fieldName, string $metaDataKeyword)

Specify a projected metadata field on which to sort the query.

Sort order is not configurable for metadata fields. Sorting by a metadata field requires the same field and $meta expression to exist in the projection document. This method will call {@link Builder::selectMeta()} if the field is not already set in the projection.

Parameters

string $fieldName Field name of the projected metadata
string $metaDataKeyword

Return Value

$this

See also

http://docs.mongodb.org/master/reference/operator/projection/meta/#sort

$this text(string $search)

Specify $text criteria for the current field.

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

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 unsetField()

Unset the current field.

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

$this updateOne(string $documentName = null)

Parameters

string $documentName

Return Value

$this

$this updateMany(string $documentName = null)

Parameters

string $documentName

Return Value

$this

$this upsert(bool $bool = true)

Set the "upsert" option for an update or findAndUpdate query.

Parameters

bool $bool

Return Value

$this

$this where(string|Javascript $javascript)

Specify a JavaScript expression to use for matching documents.

Parameters

string|Javascript $javascript

Return Value

$this

See also

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