PHP Class Sokil\Mongo\Collection

It aggregates \MongoCollection instance.
Inheritance: implements Countable
Afficher le fichier Open project: sokil/php-mongo Class Usage Examples

Protected Properties

Свойство Type Description
$_index Every index definition must contain key 'keys' with list of fields and orders, and optional options from @link http://php.net/manual/en/mongocollection.createindex.php: Example: array( array( 'keys' => array('field1' => 1, 'field2' => -1), 'unique' => true ), ... )
$_queryExpressionClass expression class. This class may be overloaded to define own query methods (whereUserAgeGreatedThan(), etc.)
$mongoCollectionClassName
$versioning default value of versioning

Méthodes publiques

Méthode Description
__construct ( Database $database, $collection, Definition $definition = null )
__get ( $name )
addDocumentToDocumentPool ( Document $document ) : Collection Store document to pool
addDocumentsToDocumentPool ( array $documents ) : Collection Store documents to identity map
aggregate ( callable | array | Pipeline $pipeline, array $options = [], boolean $asCursor = false ) : array Aggregate using pipeline
batchDelete ( callable | array | Expression $expression = [] ) : Collection Delete documents by expression
batchInsert ( array $rows, $validate = true ) : Collection Insert multiple documents defined as arrays
batchUpdate ( Expression | array | callable $expression, Operator | array | callable $updateData ) : Collection Update multiple documents
clearDocumentPool ( )
count ( ) : integer Total count of documents in collection
createAggregator ( ) : Pipeline Start aggregation
createBatchDelete ( integer | string $writeConcern = null, integer $timeout = null, boolean $ordered = null ) : Sokil\Mongo\BatchDelete Creates batch delete operation handler
createBatchInsert ( integer | string $writeConcern = null, integer $timeout = null, boolean $ordered = null ) : Sokil\Mongo\BatchInsert Creates batch insert operation handler
createBatchUpdate ( integer | string $writeConcern = null, integer $timeout = null, boolean $ordered = null ) : Sokil\Mongo\BatchUpdate Creates batch update operation handler
createDocument ( array $data = null ) : Document Factory method to get not stored Document instance from array
createIndex ( array $key, array $options = [] ) : Collection Create index
delete ( ) : Collection Delete collection
deleteDocument ( Document $document ) : Collection
deleteDocuments ( $expression = [] )
deleteIndex ( array $key ) : Collection Delete index
disableDocumentPool ( ) : Collection Stop storing found documents to pool
documentPoolCount ( ) : integer Get number of documents in document pool
enableDocumentPool ( ) : Collection Start storing found documents to pool
enableVersioning ( ) : Collection Start versioning documents on modify
ensure2dIndex ( string $field ) : Collection Create geo index 2dsphere
ensure2dSphereIndex ( string $field ) : Collection Create geo index 2dsphere
ensureFulltextIndex ( array | string $field = '$**', array $weights = null, $defaultLanguage = Language::ENGLISH, $languageOverride = null ) : Collection Create fulltext index
ensureIndex ( array $key, array $options = [] ) : Collection Create index
ensureSparseIndex ( array $key ) : Collection Create sparse index.
ensureTTLIndex ( array $key, integer $seconds ) : Collection Create TTL index
ensureUniqueIndex ( array $key, boolean $dropDups = false ) : Collection Create unique index
explainAggregate ( array | Pipeline $pipeline ) : array Explain aggregation
expression ( ) : Expression Create new Expression instance to use in query builder or update operations
find ( $callable = null ) : Cursor | Expression Create document query builder
findAsArray ( $callable = null ) : Cursor Create document query builder
getDatabase ( ) : Database
getDistinct ( string $selector, array | callable | Expression $expression = null ) : array Retrieve a list of distinct values for the given key across a collection.
getDocument ( string | MongoId $id, callable $callable = null ) : Document | array | null Get document by id If callable specified, document always loaded directly omitting document pool.
getDocumentByReference ( array $ref, boolean $useDocumentPool = true ) : Document | null Get Document instance by it's reference
getDocumentClassName ( array $documentData = null ) : string Override to define class name of document by document data
getDocumentDirectly ( string | MongoId $id, callable $callable = null ) : Document | array | null Get document by id directly omitting cache Method may return document as array if cursor configured through Cursor::asArray()
getDocumentFromDocumentPool ( string | integer | MongoId $id ) : Document Get document from identity map by it's id
getDocuments ( array $idList, callable $callable = null ) : array | null Get documents by list of id
getDocumentsFromDocumentPool ( array $ids = null ) Get documents from pool if they stored
getIndexes ( ) : array Get index info
getMongoCollection ( ) : MongoCollection Get native collection instance of mongo driver
getName ( ) : string Get name of collection
getOption ( string | integer $name ) : mixed Get option
getOptions ( )
getReadPreference ( )
getWriteConcern ( ) : integer | string Get currently active write concern on all requests to collection
hasDocument ( Document $document ) : type Check if document belongs to collection
hydrate ( array $data, $useDocumentPool = true ) : Document Factory method to get document object from array of stored document
initIndexes ( ) : Collection Create indexes based on self::$_index metadata
insert ( array $document ) : Collection Direct insert of array to MongoDB without creating document object and validation
insertMultiple ( $rows, $validate = true )
isDocumentInDocumentPool ( Document | MongoId | integer | string $document ) : boolean Check if document exists in identity map
isDocumentPoolEmpty ( ) : boolean Check if documents are in pool
isDocumentPoolEnabled ( ) : boolean Check if document pool enabled and requested documents store to it
isVersioningEnabled ( ) : boolean Check if versioning enabled
operator ( ) : Operator Create Operator instance to use in update operations
readNearest ( array $tags = null )
readPrimaryOnly ( )
readPrimaryPreferred ( array $tags = null )
readSecondaryOnly ( array $tags = null )
readSecondaryPreferred ( array $tags = null )
removeDocumentFromDocumentPool ( Document $document ) : Collection Remove document instance from identity map
setMajorityWriteConcern ( integer $timeout = 10000 ) : Collection Define majority write concern for all requests to current collection
setUnacknowledgedWriteConcern ( integer $timeout = 10000 ) : Collection Define unacknowledged write concern for all requests to current collection
setWriteConcern ( string | integer $w, integer $timeout = 10000 ) : Collection Define write concern for all requests to current collection
stats ( ) : array Get collection stat
update ( Expression | array | callable $expression, Operator | array | callable $updateData, array $options = [] ) : Collection Update multiple documents
updateAll ( Operator | array | callable $updateData ) : Collection Update all documents
updateMultiple ( $expression, $updateData )
validate ( boolean $full = false ) : array Validates a collection. The method scans a collection’s data structures for correctness and returns a single document that describes the relationship between the logical collection and the physical representation of the data.

Method Details

__construct() public méthode

public __construct ( Database $database, $collection, Definition $definition = null )
$database Database
$definition Sokil\Mongo\Collection\Definition

__get() public méthode

public __get ( $name )

addDocumentToDocumentPool() public méthode

Store document to pool
public addDocumentToDocumentPool ( Document $document ) : Collection
$document Document
Résultat Collection

addDocumentsToDocumentPool() public méthode

Store documents to identity map
public addDocumentsToDocumentPool ( array $documents ) : Collection
$documents array list of Document instances
Résultat Collection

aggregate() public méthode

Aggregate using pipeline
public aggregate ( callable | array | Pipeline $pipeline, array $options = [], boolean $asCursor = false ) : array
$pipeline callable | array | Pipeline list of pipeline stages
$options array
$asCursor boolean return result as cursor
Résultat array result of aggregation

batchDelete() public méthode

Delete documents by expression
public batchDelete ( callable | array | Expression $expression = [] ) : Collection
$expression callable | array | Expression
Résultat Collection

batchInsert() public méthode

Prior to version 1.5.0 of the driver it was possible to use MongoCollection::batchInsert(), however, as of 1.5.0 that method is now discouraged. You can use Collection::createBatchInsert()
public batchInsert ( array $rows, $validate = true ) : Collection
$rows array list of documents to insert, defined as arrays
Résultat Collection

batchUpdate() public méthode

Update multiple documents
public batchUpdate ( Expression | array | callable $expression, Operator | array | callable $updateData ) : Collection
$expression Expression | array | callable expression to define which documents will change.
$updateData Operator | array | callable new data or operators to update
Résultat Collection

clearDocumentPool() public méthode

public clearDocumentPool ( )

count() public méthode

Total count of documents in collection
public count ( ) : integer
Résultat integer

createAggregator() public méthode

Start aggregation
public createAggregator ( ) : Pipeline
Résultat Pipeline

createBatchDelete() public méthode

Creates batch delete operation handler
public createBatchDelete ( integer | string $writeConcern = null, integer $timeout = null, boolean $ordered = null ) : Sokil\Mongo\BatchDelete
$writeConcern integer | string Write concern. Default is 1 (Acknowledged)
$timeout integer Timeout for write concern. Default is 10000 milliseconds
$ordered boolean Determins if MongoDB must apply this batch in order (sequentally, one item at a time) or can rearrange it. Defaults to TRUE
Résultat Sokil\Mongo\BatchDelete

createBatchInsert() public méthode

Creates batch insert operation handler
public createBatchInsert ( integer | string $writeConcern = null, integer $timeout = null, boolean $ordered = null ) : Sokil\Mongo\BatchInsert
$writeConcern integer | string Write concern. Default is 1 (Acknowledged)
$timeout integer Timeout for write concern. Default is 10000 milliseconds
$ordered boolean Determins if MongoDB must apply this batch in order (sequentally, one item at a time) or can rearrange it. Defaults to TRUE
Résultat Sokil\Mongo\BatchInsert

createBatchUpdate() public méthode

Creates batch update operation handler
public createBatchUpdate ( integer | string $writeConcern = null, integer $timeout = null, boolean $ordered = null ) : Sokil\Mongo\BatchUpdate
$writeConcern integer | string Write concern. Default is 1 (Acknowledged)
$timeout integer Timeout for write concern. Default is 10000 milliseconds
$ordered boolean Determins if MongoDB must apply this batch in order (sequentally, one item at a time) or can rearrange it. Defaults to TRUE
Résultat Sokil\Mongo\BatchUpdate

createDocument() public méthode

Factory method to get not stored Document instance from array
public createDocument ( array $data = null ) : Document
$data array
Résultat Document

createIndex() public méthode

Create index
public createIndex ( array $key, array $options = [] ) : Collection
$key array
$options array see @link http://php.net/manual/en/mongocollection.ensureindex.php
Résultat Collection

delete() public méthode

Delete collection
public delete ( ) : Collection
Résultat Collection

deleteDocument() public méthode

Deprecation: since 1.13. Use Document::delete()
public deleteDocument ( Document $document ) : Collection
$document Document
Résultat Collection

deleteDocuments() public méthode

Deprecation: since 1.13. Use Collection::batchDelete();
public deleteDocuments ( $expression = [] )

deleteIndex() public méthode

Delete index
public deleteIndex ( array $key ) : Collection
$key array
Résultat Collection

disableDocumentPool() public méthode

Stop storing found documents to pool
public disableDocumentPool ( ) : Collection
Résultat Collection

documentPoolCount() public méthode

Get number of documents in document pool
public documentPoolCount ( ) : integer
Résultat integer

enableDocumentPool() public méthode

Start storing found documents to pool
public enableDocumentPool ( ) : Collection
Résultat Collection

enableVersioning() public méthode

Start versioning documents on modify
Deprecation: since 1.13 Use 'versioning' declaration in mapping
public enableVersioning ( ) : Collection
Résultat Collection

ensure2dIndex() public méthode

Create geo index 2dsphere
public ensure2dIndex ( string $field ) : Collection
$field string
Résultat Collection

ensure2dSphereIndex() public méthode

Create geo index 2dsphere
public ensure2dSphereIndex ( string $field ) : Collection
$field string
Résultat Collection

ensureFulltextIndex() public méthode

Create fulltext index
public ensureFulltextIndex ( array | string $field = '$**', array $weights = null, $defaultLanguage = Language::ENGLISH, $languageOverride = null ) : Collection
$field array | string definition of fields where full text index ensured. May be string to ensure index on one field, array of fields to create full text index on few fields, and widdcard '$**' to create index on all fields of collection. Default value is '$**'
$weights array For a text index, the weight of an indexed field denotes the significance of the field relative to the other indexed fields in terms of the text search score.
$defaultLanguage The default language associated with the indexed data determines the rules to parse word roots (i.e. stemming) and ignore stop words. The default language for the indexed data is english.
$languageOverride To use a field with a name other than language, include the language_override option when creating the index.
Résultat Collection

ensureIndex() public méthode

Create index
Deprecation: since 1.19 Use self::createIndex()
public ensureIndex ( array $key, array $options = [] ) : Collection
$key array
$options array see @link http://php.net/manual/en/mongocollection.ensureindex.php
Résultat Collection

ensureSparseIndex() public méthode

Sparse indexes only contain entries for documents that have the indexed field, even if the index field contains a null value. The index skips over any document that is missing the indexed field.
public ensureSparseIndex ( array $key ) : Collection
$key array An array specifying the index's fields as its keys. For each field, the value is either the index direction or index type. If specifying direction, specify 1 for ascending or -1 for descending.
Résultat Collection

ensureTTLIndex() public méthode

Create TTL index
public ensureTTLIndex ( array $key, integer $seconds ) : Collection
$key array key must be date to use TTL
$seconds integer
Résultat Collection

ensureUniqueIndex() public méthode

Create unique index
public ensureUniqueIndex ( array $key, boolean $dropDups = false ) : Collection
$key array
$dropDups boolean
Résultat Collection

explainAggregate() public méthode

Explain aggregation
Deprecation: use pipeline option 'explain' in Collection::aggregate() or method Pipeline::explain()
public explainAggregate ( array | Pipeline $pipeline ) : array
$pipeline array | Pipeline
Résultat array result

expression() public méthode

Create new Expression instance to use in query builder or update operations
public expression ( ) : Expression
Résultat Expression

find() public méthode

Create document query builder
public find ( $callable = null ) : Cursor | Expression
$callable callable|null Function to configure query builder&
Résultat Cursor | Expression

findAsArray() public méthode

Create document query builder
public findAsArray ( $callable = null ) : Cursor
Résultat Cursor

getDatabase() public méthode

public getDatabase ( ) : Database
Résultat Database

getDistinct() public méthode

Retrieve a list of distinct values for the given key across a collection.
public getDistinct ( string $selector, array | callable | Expression $expression = null ) : array
$selector string field selector
$expression array | callable | Expression expression to search documents
Résultat array distinct values

getDocument() public méthode

Method may return document as array if cursor configured through Cursor::asArray()
public getDocument ( string | MongoId $id, callable $callable = null ) : Document | array | null
$id string | MongoId
$callable callable cursor callable used to configure cursor
Résultat Document | array | null

getDocumentByReference() public méthode

Get Document instance by it's reference
public getDocumentByReference ( array $ref, boolean $useDocumentPool = true ) : Document | null
$ref array reference to document
$useDocumentPool boolean try to get document from pool or fetch document from database
Résultat Document | null

getDocumentClassName() public méthode

Override to define class name of document by document data
public getDocumentClassName ( array $documentData = null ) : string
$documentData array
Résultat string Document class data

getDocumentDirectly() public méthode

Get document by id directly omitting cache Method may return document as array if cursor configured through Cursor::asArray()
public getDocumentDirectly ( string | MongoId $id, callable $callable = null ) : Document | array | null
$id string | MongoId
$callable callable cursor callable used to configure cursor
Résultat Document | array | null

getDocumentFromDocumentPool() public méthode

Get document from identity map by it's id
public getDocumentFromDocumentPool ( string | integer | MongoId $id ) : Document
$id string | integer | MongoId
Résultat Document

getDocuments() public méthode

Get documents by list of id
public getDocuments ( array $idList, callable $callable = null ) : array | null
$idList array list of ids
$callable callable cursor callable used to configure cursor
Résultat array | null

getDocumentsFromDocumentPool() public méthode

Get documents from pool if they stored
public getDocumentsFromDocumentPool ( array $ids = null )
$ids array

getIndexes() public méthode

Get index info
public getIndexes ( ) : array
Résultat array

getMongoCollection() public méthode

Get native collection instance of mongo driver
public getMongoCollection ( ) : MongoCollection
Résultat MongoCollection

getName() public méthode

Get name of collection
public getName ( ) : string
Résultat string name of collection

getOption() public méthode

Get option
public getOption ( string | integer $name ) : mixed
$name string | integer
Résultat mixed

getOptions() public méthode

public getOptions ( )

getReadPreference() public méthode

public getReadPreference ( )

getWriteConcern() public méthode

Get currently active write concern on all requests to collection
public getWriteConcern ( ) : integer | string
Résultat integer | string write concern

hasDocument() public méthode

Check if document belongs to collection
public hasDocument ( Document $document ) : type
$document Document
Résultat type

hydrate() public méthode

Factory method to get document object from array of stored document
public hydrate ( array $data, $useDocumentPool = true ) : Document
$data array
Résultat Document

initIndexes() public méthode

Create indexes based on self::$_index metadata
public initIndexes ( ) : Collection
Résultat Collection

insert() public méthode

Direct insert of array to MongoDB without creating document object and validation
public insert ( array $document ) : Collection
$document array
Résultat Collection

insertMultiple() public méthode

Deprecation: since 1.13 Use Collection::batchInsert()
public insertMultiple ( $rows, $validate = true )

isDocumentInDocumentPool() public méthode

Check if document exists in identity map
public isDocumentInDocumentPool ( Document | MongoId | integer | string $document ) : boolean
$document Document | MongoId | integer | string Document instance or it's id
Résultat boolean

isDocumentPoolEmpty() public méthode

Check if documents are in pool
public isDocumentPoolEmpty ( ) : boolean
Résultat boolean

isDocumentPoolEnabled() public méthode

Check if document pool enabled and requested documents store to it
public isDocumentPoolEnabled ( ) : boolean
Résultat boolean

isVersioningEnabled() public méthode

Check if versioning enabled
Deprecation: since 1.13 Use 'versioning' declaration in mapping
public isVersioningEnabled ( ) : boolean
Résultat boolean

operator() public méthode

Create Operator instance to use in update operations
public operator ( ) : Operator
Résultat Operator

readNearest() public méthode

public readNearest ( array $tags = null )
$tags array

readPrimaryOnly() public méthode

public readPrimaryOnly ( )

readPrimaryPreferred() public méthode

public readPrimaryPreferred ( array $tags = null )
$tags array

readSecondaryOnly() public méthode

public readSecondaryOnly ( array $tags = null )
$tags array

readSecondaryPreferred() public méthode

public readSecondaryPreferred ( array $tags = null )
$tags array

removeDocumentFromDocumentPool() public méthode

Remove document instance from identity map
public removeDocumentFromDocumentPool ( Document $document ) : Collection
$document Document
Résultat Collection

setMajorityWriteConcern() public méthode

Define majority write concern for all requests to current collection
public setMajorityWriteConcern ( integer $timeout = 10000 ) : Collection
$timeout integer timeout in milliseconds
Résultat Collection

setUnacknowledgedWriteConcern() public méthode

Define unacknowledged write concern for all requests to current collection
public setUnacknowledgedWriteConcern ( integer $timeout = 10000 ) : Collection
$timeout integer timeout in milliseconds
Résultat Collection

setWriteConcern() public méthode

Define write concern for all requests to current collection
public setWriteConcern ( string | integer $w, integer $timeout = 10000 ) : Collection
$w string | integer write concern
$timeout integer timeout in milliseconds
Résultat Collection

stats() public méthode

Get collection stat
public stats ( ) : array
Résultat array collection stat

update() public méthode

Update multiple documents
public update ( Expression | array | callable $expression, Operator | array | callable $updateData, array $options = [] ) : Collection
$expression Expression | array | callable expression to define which documents will change.
$updateData Operator | array | callable new data or operators to update
$options array update options, see http://php.net/manual/ru/mongocollection.update.php
Résultat Collection

updateAll() public méthode

Update all documents
Deprecation: since 1.13. Use Collection::batchUpdate([])
public updateAll ( Operator | array | callable $updateData ) : Collection
$updateData Operator | array | callable new data or operators
Résultat Collection

updateMultiple() public méthode

Deprecation: since 1.13 Use Collection::batchUpdate()
public updateMultiple ( $expression, $updateData )

validate() public méthode

Validates a collection. The method scans a collection’s data structures for correctness and returns a single document that describes the relationship between the logical collection and the physical representation of the data.
public validate ( boolean $full = false ) : array
$full boolean Specify true to enable a full validation and to return full statistics. MongoDB disables full validation by default because it is a potentially resource-intensive operation.
Résultat array

Property Details

$_index protected_oe property

Every index definition must contain key 'keys' with list of fields and orders, and optional options from @link http://php.net/manual/en/mongocollection.createindex.php: Example: array( array( 'keys' => array('field1' => 1, 'field2' => -1), 'unique' => true ), ... )
Deprecation: since 1.13 Use 'index' declaration in mapping
protected $_index

$_queryExpressionClass protected_oe property

expression class. This class may be overloaded to define own query methods (whereUserAgeGreatedThan(), etc.)
Deprecation: since 1.13 Use 'expressionClass' declaration in mapping
protected $_queryExpressionClass

$mongoCollectionClassName protected_oe property

protected $mongoCollectionClassName

$versioning protected_oe property

default value of versioning
Deprecation: since 1.13 Use 'versioning' declaration in mapping
protected $versioning