PHP Класс Sokil\Mongo\Collection

It aggregates \MongoCollection instance.
Автор: Dmytro Sokil ([email protected])
Наследование: implements Countable
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_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

Открытые методы

Метод Описание
__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.

Описание методов

__construct() публичный метод

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

__get() публичный метод

public __get ( $name )

addDocumentToDocumentPool() публичный метод

Store document to pool
public addDocumentToDocumentPool ( Document $document ) : Collection
$document Document
Результат Collection

addDocumentsToDocumentPool() публичный метод

Store documents to identity map
public addDocumentsToDocumentPool ( array $documents ) : Collection
$documents array list of Document instances
Результат Collection

aggregate() публичный метод

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
Результат array result of aggregation

batchDelete() публичный метод

Delete documents by expression
public batchDelete ( callable | array | Expression $expression = [] ) : Collection
$expression callable | array | Expression
Результат Collection

batchInsert() публичный метод

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
Результат Collection

batchUpdate() публичный метод

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
Результат Collection

clearDocumentPool() публичный метод

public clearDocumentPool ( )

count() публичный метод

Total count of documents in collection
public count ( ) : integer
Результат integer

createAggregator() публичный метод

Start aggregation
public createAggregator ( ) : Pipeline
Результат Pipeline

createBatchDelete() публичный метод

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
Результат Sokil\Mongo\BatchDelete

createBatchInsert() публичный метод

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
Результат Sokil\Mongo\BatchInsert

createBatchUpdate() публичный метод

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
Результат Sokil\Mongo\BatchUpdate

createDocument() публичный метод

Factory method to get not stored Document instance from array
public createDocument ( array $data = null ) : Document
$data array
Результат Document

createIndex() публичный метод

Create index
public createIndex ( array $key, array $options = [] ) : Collection
$key array
$options array see @link http://php.net/manual/en/mongocollection.ensureindex.php
Результат Collection

delete() публичный метод

Delete collection
public delete ( ) : Collection
Результат Collection

deleteDocument() публичный метод

Устаревший: since 1.13. Use Document::delete()
public deleteDocument ( Document $document ) : Collection
$document Document
Результат Collection

deleteDocuments() публичный метод

Устаревший: since 1.13. Use Collection::batchDelete();
public deleteDocuments ( $expression = [] )

deleteIndex() публичный метод

Delete index
public deleteIndex ( array $key ) : Collection
$key array
Результат Collection

disableDocumentPool() публичный метод

Stop storing found documents to pool
public disableDocumentPool ( ) : Collection
Результат Collection

documentPoolCount() публичный метод

Get number of documents in document pool
public documentPoolCount ( ) : integer
Результат integer

enableDocumentPool() публичный метод

Start storing found documents to pool
public enableDocumentPool ( ) : Collection
Результат Collection

enableVersioning() публичный метод

Start versioning documents on modify
Устаревший: since 1.13 Use 'versioning' declaration in mapping
public enableVersioning ( ) : Collection
Результат Collection

ensure2dIndex() публичный метод

Create geo index 2dsphere
public ensure2dIndex ( string $field ) : Collection
$field string
Результат Collection

ensure2dSphereIndex() публичный метод

Create geo index 2dsphere
public ensure2dSphereIndex ( string $field ) : Collection
$field string
Результат Collection

ensureFulltextIndex() публичный метод

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.
Результат Collection

ensureIndex() публичный метод

Create index
Устаревший: 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
Результат Collection

ensureSparseIndex() публичный метод

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.
Результат Collection

ensureTTLIndex() публичный метод

Create TTL index
public ensureTTLIndex ( array $key, integer $seconds ) : Collection
$key array key must be date to use TTL
$seconds integer
Результат Collection

ensureUniqueIndex() публичный метод

Create unique index
public ensureUniqueIndex ( array $key, boolean $dropDups = false ) : Collection
$key array
$dropDups boolean
Результат Collection

explainAggregate() публичный метод

Explain aggregation
Устаревший: use pipeline option 'explain' in Collection::aggregate() or method Pipeline::explain()
public explainAggregate ( array | Pipeline $pipeline ) : array
$pipeline array | Pipeline
Результат array result

expression() публичный метод

Create new Expression instance to use in query builder or update operations
public expression ( ) : Expression
Результат Expression

find() публичный метод

Create document query builder
public find ( $callable = null ) : Cursor | Expression
$callable callable|null Function to configure query builder&
Результат Cursor | Expression

findAsArray() публичный метод

Create document query builder
public findAsArray ( $callable = null ) : Cursor
Результат Cursor

getDatabase() публичный метод

public getDatabase ( ) : Database
Результат Database

getDistinct() публичный метод

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
Результат array distinct values

getDocument() публичный метод

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
Результат Document | array | null

getDocumentByReference() публичный метод

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
Результат Document | null

getDocumentClassName() публичный метод

Override to define class name of document by document data
public getDocumentClassName ( array $documentData = null ) : string
$documentData array
Результат string Document class data

getDocumentDirectly() публичный метод

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
Результат Document | array | null

getDocumentFromDocumentPool() публичный метод

Get document from identity map by it's id
public getDocumentFromDocumentPool ( string | integer | MongoId $id ) : Document
$id string | integer | MongoId
Результат Document

getDocuments() публичный метод

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
Результат array | null

getDocumentsFromDocumentPool() публичный метод

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

getIndexes() публичный метод

Get index info
public getIndexes ( ) : array
Результат array

getMongoCollection() публичный метод

Get native collection instance of mongo driver
public getMongoCollection ( ) : MongoCollection
Результат MongoCollection

getName() публичный метод

Get name of collection
public getName ( ) : string
Результат string name of collection

getOption() публичный метод

Get option
public getOption ( string | integer $name ) : mixed
$name string | integer
Результат mixed

getOptions() публичный метод

public getOptions ( )

getReadPreference() публичный метод

public getReadPreference ( )

getWriteConcern() публичный метод

Get currently active write concern on all requests to collection
public getWriteConcern ( ) : integer | string
Результат integer | string write concern

hasDocument() публичный метод

Check if document belongs to collection
public hasDocument ( Document $document ) : type
$document Document
Результат type

hydrate() публичный метод

Factory method to get document object from array of stored document
public hydrate ( array $data, $useDocumentPool = true ) : Document
$data array
Результат Document

initIndexes() публичный метод

Create indexes based on self::$_index metadata
public initIndexes ( ) : Collection
Результат Collection

insert() публичный метод

Direct insert of array to MongoDB without creating document object and validation
public insert ( array $document ) : Collection
$document array
Результат Collection

insertMultiple() публичный метод

Устаревший: since 1.13 Use Collection::batchInsert()
public insertMultiple ( $rows, $validate = true )

isDocumentInDocumentPool() публичный метод

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
Результат boolean

isDocumentPoolEmpty() публичный метод

Check if documents are in pool
public isDocumentPoolEmpty ( ) : boolean
Результат boolean

isDocumentPoolEnabled() публичный метод

Check if document pool enabled and requested documents store to it
public isDocumentPoolEnabled ( ) : boolean
Результат boolean

isVersioningEnabled() публичный метод

Check if versioning enabled
Устаревший: since 1.13 Use 'versioning' declaration in mapping
public isVersioningEnabled ( ) : boolean
Результат boolean

operator() публичный метод

Create Operator instance to use in update operations
public operator ( ) : Operator
Результат Operator

readNearest() публичный метод

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

readPrimaryOnly() публичный метод

public readPrimaryOnly ( )

readPrimaryPreferred() публичный метод

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

readSecondaryOnly() публичный метод

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

readSecondaryPreferred() публичный метод

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

removeDocumentFromDocumentPool() публичный метод

Remove document instance from identity map
public removeDocumentFromDocumentPool ( Document $document ) : Collection
$document Document
Результат Collection

setMajorityWriteConcern() публичный метод

Define majority write concern for all requests to current collection
public setMajorityWriteConcern ( integer $timeout = 10000 ) : Collection
$timeout integer timeout in milliseconds
Результат Collection

setUnacknowledgedWriteConcern() публичный метод

Define unacknowledged write concern for all requests to current collection
public setUnacknowledgedWriteConcern ( integer $timeout = 10000 ) : Collection
$timeout integer timeout in milliseconds
Результат Collection

setWriteConcern() публичный метод

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
Результат Collection

stats() публичный метод

Get collection stat
public stats ( ) : array
Результат array collection stat

update() публичный метод

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
Результат Collection

updateAll() публичный метод

Update all documents
Устаревший: since 1.13. Use Collection::batchUpdate([])
public updateAll ( Operator | array | callable $updateData ) : Collection
$updateData Operator | array | callable new data or operators
Результат Collection

updateMultiple() публичный метод

Устаревший: since 1.13 Use Collection::batchUpdate()
public updateMultiple ( $expression, $updateData )

validate() публичный метод

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.
Результат array

Описание свойств

$_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 ), ... )
Устаревший: since 1.13 Use 'index' declaration in mapping
protected $_index

$_queryExpressionClass защищенное свойство

expression class. This class may be overloaded to define own query methods (whereUserAgeGreatedThan(), etc.)
Устаревший: since 1.13 Use 'expressionClass' declaration in mapping
protected $_queryExpressionClass

$mongoCollectionClassName защищенное свойство

protected $mongoCollectionClassName

$versioning защищенное свойство

default value of versioning
Устаревший: since 1.13 Use 'versioning' declaration in mapping
protected $versioning