class LoggableCollection extends Collection implements Loggable (View source)

Wrapper for the MongoCollection class with logging functionality.

Traits

{@internal It's used by loggable collection classes }}

Properties

protected Database $database The Database instance to which this collection belongs. from Collection
protected EventManager $eventManager The EventManager used to dispatch events. from Collection
protected MongoCollection $mongoCollection The MongoCollection instance being wrapped. from Collection
protected integer $numRetries Number of times to retry queries. from Collection
protected callable $loggerCallable The logger callable. from LoggableCollectionTrait

Methods

__construct(Database $database, MongoCollection $mongoCollection, EventManager $evm, integer $numRetries, callable $loggerCallable)

Constructor.

aggregate(array $pipeline, array $options = [])

No description

batchInsert(array $a, array $options = [])

No description

count(array $query = [], $limitOrOptions = 0, $skip = 0)

No description

createAggregationBuilder()

Creates a new aggregation builder instance.

array
createDBRef(mixed $documentOrId)

Wrapper method for MongoCollection::createDBRef().

createQueryBuilder()

Creates a new query builder instance.

deleteIndex($keys)

No description

deleteIndexes()

No description

distinct($field, array $query = [], array $options = [])

No description

drop()

No description

ensureIndex(array $keys, array $options = [])

No description

find(array $query = [], array $fields = [])

No description

findAndRemove(array $query, array $options = [])

No description

findAndUpdate(array $query, array $newObj, array $options = [])

No description

findOne(array $query = [], array $fields = [])

No description

getDatabase()

Return the database for this collection.

getDBRef(array $reference)

No description

getIndexInfo()

No description

MongoCollection
getMongoCollection()

Return the MongoCollection instance being wrapped.

string
getName()

Wrapper method for MongoCollection::getName().

array
getReadPreference()

Wrapper method for MongoCollection::getReadPreference().

boolean
setReadPreference(string $readPreference, array $tags = null)

Wrapper method for MongoCollection::setReadPreference().

boolean
getSlaveOkay()

Get whether secondary read queries are allowed for this collection.

boolean
setSlaveOkay(boolean $ok = true)

Set whether secondary read queries are allowed for this collection.

group($keys, array $initial, $reduce, array $options = [])

No description

insert(array $a, array $options = [])

No description

boolean
isFieldIndexed(string $fieldName)

Check if a given field name is indexed in MongoDB.

mapReduce($map, $reduce, $out = ['inline' => true], array $query = [], array $options = [])

No description

near($near, array $query = [], array $options = [])

No description

parallelCollectionScan(int $numCursors)

Wrapper method for MongoCollection::parallelCollectionScan()

remove(array $query, array $options = [])

No description

save(array $a, array $options = [])

No description

update($query, array $newObj, array $options = [])

No description

array|boolean
upsert(array $query, array $newObj, array $options = [])

Invokes {@link Collection::update()} with the upsert option.

validate($scanData = false)

No description

MongoCollection
__get(string $name)

Wrapper method for MongoCollection::__get().

string
__toString()

Wrapper method for MongoCollection::__toString().

doAggregate(array $pipeline, array $options = [])

Execute the aggregate command.

doAggregateCursor(array $pipeline, array $options = [])

Executes the aggregate command and returns a MongoCommandCursor.

array|boolean
doBatchInsert(array $a, array $options = [])

Execute the batchInsert query.

integer
doCount(array $query, array $options)

Execute the count command.

doDistinct(string $field, array $query, array $options)

Execute the distinct command.

array
doDrop()

Drops the collection.

doFind(array $query, array $fields)

Execute the find query.

array|null
doFindAndRemove(array $query, array $options = [])

Execute the findAndModify command with the remove option.

array|null
doFindAndUpdate(array $query, array $newObj, array $options)

Execute the findAndModify command with the update option.

array|null
doFindOne(array $query, array $fields)

Execute the findOne query.

array|null
doGetDBRef(array $reference)

Resolves a database reference.

doGroup(array|string|MongoCode $keys, array $initial, string|MongoCode $reduce, array $options)

Execute the group command.

array|boolean
doInsert(array $a, array $options)

Execute the insert query.

doMapReduce(string|MongoCode $map, string|MongoCode $reduce, array|string $out, array $query, array $options)

Execute the mapReduce command.

doNear(array|Point $near, array $query, array $options)

Execute the geoNear command.

array|boolean
doRemove(array $query, array $options)

Execute the remove query.

array|boolean
doSave(array $a, array $options)

Execute the save query.

array|boolean
doUpdate(array $query, array $newObj, array $options)

Execute the update query.

mixed
retry(Closure $retry)

Conditionally retry a closure if it yields an exception.

wrapCommandCursor(MongoCommandCursor $commandCursor)

Wraps a MongoCommandCursor instance with a CommandCursor.

wrapCursor(MongoCursor $cursor, array $query, array $fields)

Wraps a MongoCursor instance with a LoggableCursor.

array
convertWriteConcern(array $options)

Converts "safe" write option to "w" for driver versions 1.3.0+.

array
convertWriteTimeout(array $options)

Convert "wtimeout" write option to "wTimeoutMS" for driver version 1.5.0+.

array
convertSocketTimeout(array $options)

Convert "timeout" write option to "socketTimeoutMS" for driver version 1.5.0+.

array
splitCommandAndClientOptions(array $options)

Splits a command helper's options array into command and client options.

log(array $log)

Log something using the configured logger callable.

Details

__construct(Database $database, MongoCollection $mongoCollection, EventManager $evm, integer $numRetries, callable $loggerCallable)

Constructor.

Parameters

Database $database Database to which this collection belongs
MongoCollection $mongoCollection MongoCollection instance being wrapped
EventManager $evm EventManager instance
integer $numRetries Number of times to retry queries
callable $loggerCallable The logger callable

aggregate(array $pipeline, array $options = [])

Parameters

array $pipeline
array $options

See also

Collection::aggregate()

batchInsert(array $a, array $options = [])

Parameters

array $a
array $options

See also

Collection::batchInsert()

count(array $query = [], $limitOrOptions = 0, $skip = 0)

Parameters

array $query
$limitOrOptions
$skip

See also

Collection::count()

Builder createAggregationBuilder()

Creates a new aggregation builder instance.

Return Value

Builder

array createDBRef(mixed $documentOrId)

Wrapper method for MongoCollection::createDBRef().

Parameters

mixed $documentOrId

Return Value

array

See also

http://php.net/manual/en/mongocollection.createdbref.php

Builder createQueryBuilder()

Creates a new query builder instance.

Return Value

Builder

deleteIndex($keys)

Parameters

$keys

See also

Collection::deleteIndex()

deleteIndexes()

See also

Collection::deleteIndexes()

distinct($field, array $query = [], array $options = [])

Parameters

$field
array $query
array $options

See also

Collection::distinct()

drop()

See also

Collection::drop()

ensureIndex(array $keys, array $options = [])

Parameters

array $keys
array $options

See also

Collection::ensureIndex()

find(array $query = [], array $fields = [])

Parameters

array $query
array $fields

See also

Collection::find()

findAndRemove(array $query, array $options = [])

Parameters

array $query
array $options

See also

Collection::findAndRemove()

findAndUpdate(array $query, array $newObj, array $options = [])

Parameters

array $query
array $newObj
array $options

See also

Collection::findAndUpdate()

findOne(array $query = [], array $fields = [])

Parameters

array $query
array $fields

See also

Collection::findOne()

Database getDatabase()

Return the database for this collection.

Return Value

Database

getDBRef(array $reference)

Parameters

array $reference

See also

Collection::getDBRef()

getIndexInfo()

See also

Collection::getIndexInfo()

MongoCollection getMongoCollection()

Return the MongoCollection instance being wrapped.

Return Value

MongoCollection

string getName()

Wrapper method for MongoCollection::getName().

array getReadPreference()

Wrapper method for MongoCollection::getReadPreference().

For driver versions between 1.3.0 and 1.3.3, the return value will be converted for consistency with {@link Collection::setReadPreference()}.

boolean setReadPreference(string $readPreference, array $tags = null)

Wrapper method for MongoCollection::setReadPreference().

Parameters

string $readPreference
array $tags

Return Value

boolean

See also

http://php.net/manual/en/mongocollection.setreadpreference.php

boolean getSlaveOkay()

Get whether secondary read queries are allowed for this collection.

This method wraps getSlaveOkay() for driver versions before 1.3.0. For newer drivers, this method considers any read preference other than PRIMARY as a true "slaveOkay" value.

boolean setSlaveOkay(boolean $ok = true)

Set whether secondary read queries are allowed for this collection.

This method wraps setSlaveOkay() for driver versions before 1.3.0. For newer drivers, this method wraps setReadPreference() and specifies SECONDARY_PREFERRED.

group($keys, array $initial, $reduce, array $options = [])

Parameters

$keys
array $initial
$reduce
array $options

See also

Collection::group()

insert(array $a, array $options = [])

Parameters

array $a
array $options

See also

Collection::insert()

boolean isFieldIndexed(string $fieldName)

Check if a given field name is indexed in MongoDB.

Parameters

string $fieldName

Return Value

boolean

mapReduce($map, $reduce, $out = ['inline' => true], array $query = [], array $options = [])

Parameters

$map
$reduce
$out
array $query
array $options

See also

Collection::mapReduce()

near($near, array $query = [], array $options = [])

Parameters

$near
array $query
array $options

See also

Collection::near()

CommandCursor[] parallelCollectionScan(int $numCursors)

Wrapper method for MongoCollection::parallelCollectionScan()

Parameters

int $numCursors

Return Value

CommandCursor[]

Exceptions

BadMethodCallException if MongoCollection::parallelCollectionScan() is not available

remove(array $query, array $options = [])

Parameters

array $query
array $options

See also

Collection::remove()

save(array $a, array $options = [])

Parameters

array $a
array $options

See also

Collection::save()

update($query, array $newObj, array $options = [])

Parameters

$query
array $newObj
array $options

See also

Collection::update()

array|boolean upsert(array $query, array $newObj, array $options = [])

Invokes {@link Collection::update()} with the upsert option.

This method will dispatch preUpdate and postUpdate events.

Parameters

array $query
array $newObj
array $options

Return Value

array|boolean

See also

Collection::update
http://php.net/manual/en/mongocollection.update.php

validate($scanData = false)

Parameters

$scanData

See also

Collection::validate()

MongoCollection __get(string $name)

Wrapper method for MongoCollection::__get().

Parameters

string $name

Return Value

MongoCollection

See also

http://php.net/manual/en/mongocollection.get.php

string __toString()

Wrapper method for MongoCollection::__toString().

protected Iterator doAggregate(array $pipeline, array $options = [])

Execute the aggregate command.

Parameters

array $pipeline
array $options

Return Value

Iterator

See also

Collection::aggregate

protected CommandCursor doAggregateCursor(array $pipeline, array $options = [])

Executes the aggregate command and returns a MongoCommandCursor.

Parameters

array $pipeline
array $options

Return Value

CommandCursor

Exceptions

BadMethodCallException if MongoCollection::aggregateCursor() is not available

protected array|boolean doBatchInsert(array $a, array $options = [])

Execute the batchInsert query.

Parameters

array $a
array $options

Return Value

array|boolean

See also

Collection::batchInsert

protected integer doCount(array $query, array $options)

Execute the count command.

Parameters

array $query
array $options

Return Value

integer

Exceptions

ResultException if the command fails or omits the result field

See also

Collection::count

protected ArrayIterator doDistinct(string $field, array $query, array $options)

Execute the distinct command.

Parameters

string $field
array $query
array $options

Return Value

ArrayIterator

Exceptions

ResultException if the command fails

See also

Collection::distinct

protected array doDrop()

Drops the collection.

Return Value

array

See also

Collection::drop

protected Cursor doFind(array $query, array $fields)

Execute the find query.

Parameters

array $query
array $fields

Return Value

Cursor

See also

Collection::find

protected array|null doFindAndRemove(array $query, array $options = [])

Execute the findAndModify command with the remove option.

Parameters

array $query
array $options

Return Value

array|null

Exceptions

ResultException if the command fails

See also

Collection::findAndRemove

protected array|null doFindAndUpdate(array $query, array $newObj, array $options)

Execute the findAndModify command with the update option.

Parameters

array $query
array $newObj
array $options

Return Value

array|null

Exceptions

ResultException if the command fails

See also

Collection::findAndUpdate

protected array|null doFindOne(array $query, array $fields)

Execute the findOne query.

Parameters

array $query
array $fields

Return Value

array|null

See also

Collection::findOne

protected array|null doGetDBRef(array $reference)

Resolves a database reference.

Parameters

array $reference

Return Value

array|null

See also

Collection::getDBRef

protected ArrayIterator doGroup(array|string|MongoCode $keys, array $initial, string|MongoCode $reduce, array $options)

Execute the group command.

Parameters

array|string|MongoCode $keys
array $initial
string|MongoCode $reduce
array $options

Return Value

ArrayIterator

Exceptions

ResultException if the command fails

See also

Collection::group

protected array|boolean doInsert(array $a, array $options)

Execute the insert query.

Parameters

array $a
array $options

Return Value

array|boolean

See also

Collection::insert

protected ArrayIterator doMapReduce(string|MongoCode $map, string|MongoCode $reduce, array|string $out, array $query, array $options)

Execute the mapReduce command.

Parameters

string|MongoCode $map
string|MongoCode $reduce
array|string $out
array $query
array $options

Return Value

ArrayIterator

Exceptions

ResultException if the command fails

See also

Collection::mapReduce

protected ArrayIterator doNear(array|Point $near, array $query, array $options)

Execute the geoNear command.

Parameters

array|Point $near
array $query
array $options

Return Value

ArrayIterator

Exceptions

ResultException if the command fails

See also

Collection::near

protected array|boolean doRemove(array $query, array $options)

Execute the remove query.

Parameters

array $query
array $options

Return Value

array|boolean

See also

Collection::remove

protected array|boolean doSave(array $a, array $options)

Execute the save query.

Parameters

array $a
array $options

Return Value

array|boolean

See also

Collection::save

protected array|boolean doUpdate(array $query, array $newObj, array $options)

Execute the update query.

Parameters

array $query
array $newObj
array $options

Return Value

array|boolean

See also

Collection::update

protected mixed retry(Closure $retry)

Conditionally retry a closure if it yields an exception.

If the closure does not return successfully within the configured number of retries, its first exception will be thrown.

This method should not be used for write operations.

Parameters

Closure $retry

Return Value

mixed

protected CommandCursor wrapCommandCursor(MongoCommandCursor $commandCursor)

Wraps a MongoCommandCursor instance with a CommandCursor.

Parameters

MongoCommandCursor $commandCursor

Return Value

CommandCursor

protected Cursor wrapCursor(MongoCursor $cursor, array $query, array $fields)

Wraps a MongoCursor instance with a LoggableCursor.

Parameters

MongoCursor $cursor
array $query
array $fields

Return Value

Cursor

See also

Collection::wrapCursor

protected array convertWriteConcern(array $options)

Converts "safe" write option to "w" for driver versions 1.3.0+.

Parameters

array $options

Return Value

array

protected array convertWriteTimeout(array $options)

Convert "wtimeout" write option to "wTimeoutMS" for driver version 1.5.0+.

Parameters

array $options

Return Value

array

protected array convertSocketTimeout(array $options)

Convert "timeout" write option to "socketTimeoutMS" for driver version 1.5.0+.

Parameters

array $options

Return Value

array

protected array splitCommandAndClientOptions(array $options)

Splits a command helper's options array into command and client options.

Command options are intended to be merged into the command document. Client options (e.g. socket timeout) are for {@link Database::command()}.

Parameters

array $options

Return Value

array Tuple of command options and client options

log(array $log)

Log something using the configured logger callable.

Parameters

array $log

See also

Loggable::log()