PHP Class Phalcon\Db\Adapter\MongoDB\Collection

Show file Open project: phalcon/incubator

Public Methods

Method Description
__construct ( MongoDB\Driver\Manager $manager, string $databaseName, string $collectionName, array $options = [] ) Constructs new Collection instance.
__debugInfo ( ) : array Return internal properties for debugging purposes.
__toString ( ) : string Return the collection namespace (e.g. "db.collection").
aggregate ( array $pipeline, array $options = [] ) : Traversable Executes an aggregation framework pipeline on the collection.
bulkWrite ( array $operations, array $options = [] ) : BulkWriteResult Executes multiple write operations.
count ( array | object $filter = [], array $options = [] ) : integer Gets the number of documents matching the filter.
createIndex ( array | object $key, array $options = [] ) : string Create a single index for the collection.
createIndexes ( array $indexes ) : string[] Create one or more indexes for the collection.
deleteMany ( array | object $filter, array $options = [] ) : DeleteResult Deletes all documents matching the filter.
deleteOne ( array | object $filter, array $options = [] ) : DeleteResult Deletes at most one document matching the filter.
distinct ( string $fieldName, array | object $filter = [], array $options = [] ) : mixed[] Finds the distinct values for a specified field across the collection.
drop ( array $options = [] ) : array | object Drop this collection.
dropIndex ( string $indexName, array $options = [] ) : array | object Drop a single index in the collection.
dropIndexes ( array $options = [] ) : array | object Drop all indexes in the collection.
find ( array | object $filter = [], array $options = [] ) : MongoDB\Driver\Cursor Finds documents matching the query.
findOne ( array | object $filter = [], array $options = [] ) : array | object | null Finds a single document matching the query.
findOneAndDelete ( array | object $filter, array $options = [] ) : object | null Finds a single document and deletes it, returning the original.
findOneAndReplace ( array | object $filter, array | object $replacement, array $options = [] ) : object | null Finds a single document and replaces it, returning either the original or the replaced document.
findOneAndUpdate ( array | object $filter, array | object $update, array $options = [] ) : object | null Finds a single document and updates it, returning either the original or the updated document.
getCollectionName ( ) : string Return the collection name.
getDatabaseName ( ) : string Return the database name.
getNamespace ( ) : string Return the collection namespace.
insertMany ( array $documents, array $options = [] ) : InsertManyResult Inserts multiple documents.
insertOne ( array | object $document, array $options = [] ) : InsertOneResult Inserts one document.
listIndexes ( array $options = [] ) : Phalcon\Db\Adapter\MongoDB\Model\IndexInfoIterator Returns information for all indexes for the collection.
replaceOne ( array | object $filter, array | object $replacement, array $options = [] ) : UpdateResult Replaces at most one document matching the filter.
updateMany ( array | object $filter, array | object $update, array $options = [] ) : UpdateResult Updates all documents matching the filter.
updateOne ( array | object $filter, array | object $update, array $options = [] ) : UpdateResult Updates at most one document matching the filter.
withOptions ( array $options = [] ) : Collection Get a clone of this collection with different options.

Method Details

__construct() public method

This class provides methods for collection-specific operations, such as CRUD (i.e. create, read, update, and delete) and index management. Supported options: * readConcern (MongoDB\Driver\ReadConcern): The default read concern to use for collection operations. Defaults to the Manager's read concern. * readPreference (MongoDB\Driver\ReadPreference): The default read preference to use for collection operations. Defaults to the Manager's read preference. * typeMap (array): Default type map for cursors and BSON documents. * writeConcern (MongoDB\Driver\WriteConcern): The default write concern to use for collection operations. Defaults to the Manager's write concern.
public __construct ( MongoDB\Driver\Manager $manager, string $databaseName, string $collectionName, array $options = [] )
$manager MongoDB\Driver\Manager Manager instance from the driver
$databaseName string Database name
$collectionName string Collection name
$options array Collection options

__debugInfo() public method

Return internal properties for debugging purposes.
See also: http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
public __debugInfo ( ) : array
return array

__toString() public method

Return the collection namespace (e.g. "db.collection").
See also: https://docs.mongodb.org/manual/faq/developers/#faq-dev-namespace
public __toString ( ) : string
return string

aggregate() public method

Note: this method's return value depends on the MongoDB server version and the "useCursor" option. If "useCursor" is true, a Cursor will be returned; otherwise, an ArrayIterator is returned, which wraps the "result" array from the command response document. Note: BSON deserialization of inline aggregation results (i.e. not using a command cursor) does not yet support a custom type map (depends on: https://jira.mongodb.org/browse/PHPC-314).
See also: Aggregate::__construct() for supported options
public aggregate ( array $pipeline, array $options = [] ) : Traversable
$pipeline array List of pipeline operations
$options array Command options
return Traversable

bulkWrite() public method

Executes multiple write operations.
See also: BulkWrite::__construct() for supported options
public bulkWrite ( array $operations, array $options = [] ) : BulkWriteResult
$operations array List of write operations
$options array Command options
return BulkWriteResult

count() public method

Gets the number of documents matching the filter.
See also: Count::__construct() for supported options
public count ( array | object $filter = [], array $options = [] ) : integer
$filter array | object Query by which to filter documents
$options array Command options
return integer

createIndex() public method

Create a single index for the collection.
See also: Collection::createIndexes()
public createIndex ( array | object $key, array $options = [] ) : string
$key array | object Document containing fields mapped to values, which denote order or an index type
$options array Index options
return string The name of the created index

createIndexes() public method

Each element in the $indexes array must have a "key" document, which contains fields mapped to an order or type. Other options may follow. For example: $indexes = [ Create a unique index on the "username" field [ 'key' => [ 'username' => 1 ], 'unique' => true ], Create a 2dsphere index on the "loc" field with a custom name [ 'key' => [ 'loc' => '2dsphere' ], 'name' => 'geo' ], ]; If the "name" option is unspecified, a name will be generated from the "key" document.
See also: http://docs.mongodb.org/manual/reference/command/createIndexes/
See also: http://docs.mongodb.org/manual/reference/method/db.collection.createIndex/
public createIndexes ( array $indexes ) : string[]
$indexes array List of index specifications
return string[] The names of the created indexes

deleteMany() public method

Deletes all documents matching the filter.
See also: DeleteMany::__construct() for supported options
See also: http://docs.mongodb.org/manual/reference/command/delete/
public deleteMany ( array | object $filter, array $options = [] ) : DeleteResult
$filter array | object Query by which to delete documents
$options array Command options
return DeleteResult

deleteOne() public method

Deletes at most one document matching the filter.
See also: DeleteOne::__construct() for supported options
See also: http://docs.mongodb.org/manual/reference/command/delete/
public deleteOne ( array | object $filter, array $options = [] ) : DeleteResult
$filter array | object Query by which to delete documents
$options array Command options
return DeleteResult

distinct() public method

Finds the distinct values for a specified field across the collection.
See also: Distinct::__construct() for supported options
public distinct ( string $fieldName, array | object $filter = [], array $options = [] ) : mixed[]
$fieldName string Field for which to return distinct values
$filter array | object Query by which to filter documents
$options array Command options
return mixed[]

drop() public method

Drop this collection.
See also: DropCollection::__construct() for supported options
public drop ( array $options = [] ) : array | object
$options array Additional options
return array | object Command result document

dropIndex() public method

Drop a single index in the collection.
See also: DropIndexes::__construct() for supported options
public dropIndex ( string $indexName, array $options = [] ) : array | object
$indexName string Index name
$options array Additional options
return array | object Command result document

dropIndexes() public method

Drop all indexes in the collection.
See also: DropIndexes::__construct() for supported options
public dropIndexes ( array $options = [] ) : array | object
$options array Additional options
return array | object Command result document

find() public method

Finds documents matching the query.
See also: Find::__construct() for supported options
See also: http://docs.mongodb.org/manual/core/read-operations-introduction/
public find ( array | object $filter = [], array $options = [] ) : MongoDB\Driver\Cursor
$filter array | object Query by which to filter documents
$options array Additional options
return MongoDB\Driver\Cursor

findOne() public method

Finds a single document matching the query.
See also: FindOne::__construct() for supported options
See also: http://docs.mongodb.org/manual/core/read-operations-introduction/
public findOne ( array | object $filter = [], array $options = [] ) : array | object | null
$filter array | object Query by which to filter documents
$options array Additional options
return array | object | null

findOneAndDelete() public method

The document to return may be null if no document matched the filter. Note: BSON deserialization of the returned document does not yet support a custom type map (depends on: https://jira.mongodb.org/browse/PHPC-314).
See also: FindOneAndDelete::__construct() for supported options
See also: http://docs.mongodb.org/manual/reference/command/findAndModify/
public findOneAndDelete ( array | object $filter, array $options = [] ) : object | null
$filter array | object Query by which to filter documents
$options array Command options
return object | null

findOneAndReplace() public method

The document to return may be null if no document matched the filter. By default, the original document is returned. Specify FindOneAndReplace::RETURN_DOCUMENT_AFTER for the "returnDocument" option to return the updated document. Note: BSON deserialization of the returned document does not yet support a custom type map (depends on: https://jira.mongodb.org/browse/PHPC-314).
See also: FindOneAndReplace::__construct() for supported options
See also: http://docs.mongodb.org/manual/reference/command/findAndModify/
public findOneAndReplace ( array | object $filter, array | object $replacement, array $options = [] ) : object | null
$filter array | object Query by which to filter documents
$replacement array | object Replacement document
$options array Command options
return object | null

findOneAndUpdate() public method

The document to return may be null if no document matched the filter. By default, the original document is returned. Specify FindOneAndUpdate::RETURN_DOCUMENT_AFTER for the "returnDocument" option to return the updated document. Note: BSON deserialization of the returned document does not yet support a custom type map (depends on: https://jira.mongodb.org/browse/PHPC-314).
See also: FindOneAndReplace::__construct() for supported options
See also: http://docs.mongodb.org/manual/reference/command/findAndModify/
public findOneAndUpdate ( array | object $filter, array | object $update, array $options = [] ) : object | null
$filter array | object Query by which to filter documents
$update array | object Update to apply to the matched document
$options array Command options
return object | null

getCollectionName() public method

Return the collection name.
public getCollectionName ( ) : string
return string

getDatabaseName() public method

Return the database name.
public getDatabaseName ( ) : string
return string

getNamespace() public method

Return the collection namespace.
See also: https://docs.mongodb.org/manual/reference/glossary/#term-namespace
public getNamespace ( ) : string
return string

insertMany() public method

Inserts multiple documents.
See also: InsertMany::__construct() for supported options
See also: http://docs.mongodb.org/manual/reference/command/insert/
public insertMany ( array $documents, array $options = [] ) : InsertManyResult
$documents array The documents to insert
$options array Command options
return InsertManyResult

insertOne() public method

Inserts one document.
See also: InsertOne::__construct() for supported options
See also: http://docs.mongodb.org/manual/reference/command/insert/
public insertOne ( array | object $document, array $options = [] ) : InsertOneResult
$document array | object The document to insert
$options array Command options
return InsertOneResult

listIndexes() public method

Returns information for all indexes for the collection.
See also: ListIndexes::__construct() for supported options
public listIndexes ( array $options = [] ) : Phalcon\Db\Adapter\MongoDB\Model\IndexInfoIterator
$options array
return Phalcon\Db\Adapter\MongoDB\Model\IndexInfoIterator

replaceOne() public method

Replaces at most one document matching the filter.
See also: ReplaceOne::__construct() for supported options
See also: http://docs.mongodb.org/manual/reference/command/update/
public replaceOne ( array | object $filter, array | object $replacement, array $options = [] ) : UpdateResult
$filter array | object Query by which to filter documents
$replacement array | object Replacement document
$options array Command options
return UpdateResult

updateMany() public method

Updates all documents matching the filter.
See also: UpdateMany::__construct() for supported options
See also: http://docs.mongodb.org/manual/reference/command/update/
public updateMany ( array | object $filter, array | object $update, array $options = [] ) : UpdateResult
$filter array | object Query by which to filter documents
$update array | object Update to apply to the matched documents
$options array Command options
return UpdateResult

updateOne() public method

Updates at most one document matching the filter.
See also: UpdateOne::__construct() for supported options
See also: http://docs.mongodb.org/manual/reference/command/update/
public updateOne ( array | object $filter, array | object $update, array $options = [] ) : UpdateResult
$filter array | object Query by which to filter documents
$update array | object Update to apply to the matched document
$options array Command options
return UpdateResult

withOptions() public method

Get a clone of this collection with different options.
See also: Collection::__construct() for supported options
public withOptions ( array $options = [] ) : Collection
$options array Collection constructor options
return Collection