PHP Class MongoCollection, horde

Exibir arquivo Open project: horde/horde Class Usage Examples

Public Properties

Property Type Description
$db MongoDB

Protected Properties

Property Type Description
$collection MongoDB\Collection
$name string

Public Methods

Method Description
__construct ( MongoDB $db, string $name ) Creates a new collection
__get ( string $name ) : MongoCollection Gets a collection
__set ( string $name, mixed $value )
__sleep ( ) : array
__toString ( ) : string String representation of this collection
aggregate ( array $pipeline, array $op = [] ) : array Perform an aggregation using the aggregation framework
aggregateCursor ( array $pipeline, array $options = [] ) : MongoCommandCursor Execute an aggregation pipeline command and retrieve results through a cursor
batchInsert ( array &$a, array $options = [] ) : mixed Inserts multiple documents into this collection
count ( array | stdClass $query = [], array $options = [] ) : integer Counts the number of documents in this collection
createDBRef ( array | object $document_or_id ) : array Creates a database reference
createIndex ( array $keys, array $options = [] ) : array Creates an index on the given field(s), or does nothing if the index already exists
deleteIndex ( string | array $keys ) : array Deletes an index from this collection
deleteIndexes ( ) : array Delete all indexes for this collection
distinct ( string $key, array $query = [] ) : array | boolean Retrieve a list of distinct values for the given key across a collection
drop ( ) : array Drops this collection
ensureIndex ( array $keys, array $options = [] ) : array Creates an index on the given field(s), or does nothing if the index already exists
find ( array $query = [], array $fields = [] ) : MongoCursor Querys this collection
findAndModify ( array $query, array $update = null, array $fields = null, array $options = [] ) : array Update a document and return it
findOne ( array $query = [], array $fields = [], array $options = [] ) : array | null Querys this collection, returning a single element
getCollection ( ) : MongoDB\Collection Gets the underlying collection for this object
getDBRef ( array $ref ) : array Fetches the document pointed to by a database reference
getIndexInfo ( ) : array Returns an array of index names for this collection
getName ( ) : string Returns this collection's name
group ( mixed $keys, array $initial, MongoCode | string $reduce, array $condition = [] ) : array Performs an operation similar to SQL's GROUP BY command
insert ( array | object &$a, array $options = [] ) : boolean | array Inserts an array into the collection
parallelCollectionScan ( integer $num_cursors ) : MongoCommandCursor[] Returns an array of cursors to iterator over a full collection in parallel
remove ( array $criteria = [], array $options = [] ) : boolean | array Remove records from this collection
save ( array | object &$a, array $options = [] ) : array | boolean Saves an object to this collection
setReadPreference ( $readPreference, $tags = null )
setWriteConcern ( $wstring, $wtimeout )
update ( array $criteria, array $newobj, array $options = [] ) : boolean Update records based on a given criteria
validate ( boolean $scan_data = FALSE ) : array Validates this collection

Protected Methods

Method Description
notImplemented ( )

Private Methods

Method Description
checkCollectionName ( $name )
convertWriteConcernOptions ( array $options ) : array Converts legacy write concern options to a WriteConcern object
createCollectionObject ( ) : MongoDB\Collection
ensureDocumentHasMongoId ( array | object &$document ) : MongoId

Method Details

__construct() public method

Creates a new collection
public __construct ( MongoDB $db, string $name )
$db MongoDB Parent database.
$name string Name for this collection.

__get() public method

Gets a collection
public __get ( string $name ) : MongoCollection
$name string The next string in the collection name.
return MongoCollection

__set() public method

public __set ( string $name, mixed $value )
$name string
$value mixed

__sleep() public method

public __sleep ( ) : array
return array

__toString() public method

String representation of this collection
public __toString ( ) : string
return string Returns the full name of this collection.

aggregate() public method

Perform an aggregation using the aggregation framework
public aggregate ( array $pipeline, array $op = [] ) : array
$pipeline array
$op array
return array

aggregateCursor() public method

Execute an aggregation pipeline command and retrieve results through a cursor
public aggregateCursor ( array $pipeline, array $options = [] ) : MongoCommandCursor
$pipeline array
$options array
return MongoCommandCursor

batchInsert() public method

Inserts multiple documents into this collection
public batchInsert ( array &$a, array $options = [] ) : mixed
$a array An array of arrays.
$options array Options for the inserts.
return mixed If "safe" is set, returns an associative array with the status of the inserts ("ok") and any error that may have occured ("err"). Otherwise, returns TRUE if the batch insert was successfully sent, FALSE otherwise.

count() public method

Counts the number of documents in this collection
public count ( array | stdClass $query = [], array $options = [] ) : integer
$query array | stdClass
$options array
return integer Returns the number of documents matching the query.

createDBRef() public method

Creates a database reference
public createDBRef ( array | object $document_or_id ) : array
$document_or_id array | object Object to which to create a reference.
return array Returns a database reference array.

createIndex() public method

Creates an index on the given field(s), or does nothing if the index already exists
public createIndex ( array $keys, array $options = [] ) : array
$keys array Field or fields to use as index.
$options array [optional] This parameter is an associative array of the form array("optionname" => , ...).
return array Returns the database response.

deleteIndex() public method

Deletes an index from this collection
public deleteIndex ( string | array $keys ) : array
$keys string | array Field or fields from which to delete the index.
return array Returns the database response.

deleteIndexes() public method

Delete all indexes for this collection
public deleteIndexes ( ) : array
return array Returns the database response.

distinct() public method

Retrieve a list of distinct values for the given key across a collection
public distinct ( string $key, array $query = [] ) : array | boolean
$key string The key to use.
$query array An optional query parameters
return array | boolean Returns an array of distinct values, or FALSE on failure

drop() public method

Drops this collection
public drop ( ) : array
return array Returns the database response.

ensureIndex() public method

Creates an index on the given field(s), or does nothing if the index already exists
Deprecation: Use MongoCollection::createIndex() instead.
public ensureIndex ( array $keys, array $options = [] ) : array
$keys array Field or fields to use as index.
$options array [optional] This parameter is an associative array of the form array("optionname" => , ...).
return array Returns the database response.

find() public method

Querys this collection
public find ( array $query = [], array $fields = [] ) : MongoCursor
$query array The fields for which to search.
$fields array Fields of the results to return.
return MongoCursor

findAndModify() public method

Update a document and return it
public findAndModify ( array $query, array $update = null, array $fields = null, array $options = [] ) : array
$query array The query criteria to search for.
$update array The update criteria.
$fields array Optionally only return these fields.
$options array An array of options to apply, such as remove the match document from the DB and return it.
return array Returns the original document, or the modified document when new is set.

findOne() public method

Querys this collection, returning a single element
public findOne ( array $query = [], array $fields = [], array $options = [] ) : array | null
$query array The fields for which to search.
$fields array Fields of the results to return.
$options array
return array | null

getCollection() public method

Gets the underlying collection for this object
public getCollection ( ) : MongoDB\Collection
return MongoDB\Collection

getDBRef() public method

Fetches the document pointed to by a database reference
public getDBRef ( array $ref ) : array
$ref array A database reference.
return array Returns the database document pointed to by the reference.

getIndexInfo() public method

Returns an array of index names for this collection
public getIndexInfo ( ) : array
return array Returns a list of index names.

getName() public method

Returns this collection's name
public getName ( ) : string
return string

group() public method

Performs an operation similar to SQL's GROUP BY command
public group ( mixed $keys, array $initial, MongoCode | string $reduce, array $condition = [] ) : array
$keys mixed Fields to group by. If an array or non-code object is passed, it will be the key used to group results.
$initial array Initial value of the aggregation counter object.
$reduce MongoCode | string A function that aggregates (reduces) the objects iterated.
$condition array An condition that must be true for a row to be considered.
return array

insert() public method

Inserts an array into the collection
public insert ( array | object &$a, array $options = [] ) : boolean | array
$a array | object
$options array
return boolean | array Returns an array containing the status of the insertion if the "w" option is set.

notImplemented() protected method

protected notImplemented ( )

parallelCollectionScan() public method

Returns an array of cursors to iterator over a full collection in parallel
public parallelCollectionScan ( integer $num_cursors ) : MongoCommandCursor[]
$num_cursors integer The number of cursors to request from the server. Please note, that the server can return less cursors than you requested.
return MongoCommandCursor[]

remove() public method

Remove records from this collection
public remove ( array $criteria = [], array $options = [] ) : boolean | array
$criteria array Query criteria for the documents to delete.
$options array An array of options for the remove operation.
return boolean | array Returns an array containing the status of the removal if the "w" option is set. Otherwise, returns TRUE.

save() public method

Saves an object to this collection
public save ( array | object &$a, array $options = [] ) : array | boolean
$a array | object Array to save. If an object is used, it may not have protected or private properties.
$options array Options for the save.
return array | boolean If w was set, returns an array containing the status of the save. Otherwise, returns a boolean representing if the array was not empty (an empty array will not be inserted).

setReadPreference() public method

public setReadPreference ( $readPreference, $tags = null )

setWriteConcern() public method

public setWriteConcern ( $wstring, $wtimeout )

update() public method

Update records based on a given criteria
public update ( array $criteria, array $newobj, array $options = [] ) : boolean
$criteria array Description of the objects to update.
$newobj array The object with which to update the matching records.
$options array
return boolean

validate() public method

Validates this collection
public validate ( boolean $scan_data = FALSE ) : array
$scan_data boolean Only validate indices, not the base collection.
return array Returns the database's evaluation of this object.

Property Details

$collection protected_oe property

protected Collection,MongoDB $collection
return MongoDB\Collection

$db public_oe property

public MongoDB $db
return MongoDB

$name protected_oe property

protected string $name
return string