PHP Interface Webiny\Component\Mongo\Bridge\MongoInterface

Show file Open project: Webiny/Framework Interface Usage Examples

Public Methods

Method Description
aggregate ( string $collectionName, array $pipeline, array $options = [] ) : Traversable Executes an aggregation framework pipeline on the collection.
bulkWrite ( string $collectionName, array $operations, array $options = [] ) : MongoDB\BulkWriteResult Executes multiple write operations.
command ( array | object $command, array $options = [] ) : MongoDB\Driver\Cursor Execute a command on this database.
connect ( $uri, array $uriOptions = [], array $driverOptions = [] ) : mixed Connect to Mongo instance
count ( string $collectionName, array | object $filter = [], array $options = [] ) : integer Gets the number of documents matching the filter.
createCollection ( string $collectionName, array $options = [] ) : array | object Create collection.
createIndex ( string $collectionName, array | object $key, array $options = [] ) : string Create a single index for the collection.
createIndexes ( string $collectionName, array $indexes ) : string[] Create one or more indexes for the collection.
delete ( string $collectionName, array | object $filter, array $options = [] ) : MongoDB\DeleteResult Deletes all documents matching the filter.
distinct ( string $collectionName, string $fieldName, array | object $filter = [], array $options = [] ) : mixed[] Finds the distinct values for a specified field across the collection.
dropCollection ( string $collectionName, array $options = [] ) : array | object Drop this collection.
dropIndex ( string $collectionName, string $indexName, array $options = [] ) : array | object Drop a single index in the collection.
dropIndexes ( string $collectionName, array $options = [] ) : array | object Drop all indexes in the collection.
find ( string $collectionName, array | object $filter = [], array $options = [] ) : MongoDB\Driver\Cursor Finds documents matching the query.
findOne ( string $collectionName, array | object $filter = [], array $options = [] ) : object | null Finds a single document matching the query.
findOneAndDelete ( string $collectionName, array | object $filter, array $options = [] ) : object | null Finds a single document and deletes it, returning the original.
findOneAndReplace ( string $collectionName, 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 ( string $collectionName, 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.
getNamespace ( string $collectionName ) : string Return the collection namespace.
id ( null | string $id = null ) : mixed Create a mongo ID instance
insertMany ( string $collectionName, array $documents, array $options = [] ) : MongoDB\InsertManyResult Inserts multiple documents.
insertOne ( string $collectionName, array | object $document, array $options = [] ) : MongoDB\InsertOneResult Inserts one document.
isId ( mixed $id ) : boolean Check if given string/object is a valid mongo ID.
listCollections ( array $options = [] ) : mixed Returns information for all collections.
listIndexes ( string $collectionName, array $options = [] ) : MongoDB\Model\IndexInfoIterator Returns information for all indexes for the collection.
selectDatabase ( string $database ) Select database
update ( string $collectionName, array | object $filter, array | object $update, array $options = [] ) : MongoDB\UpdateResult Updates all documents matching the filter.

Method Details

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).
public aggregate ( string $collectionName, array $pipeline, array $options = [] ) : Traversable
$collectionName string
$pipeline array List of pipeline operations
$options array Command options
return Traversable

bulkWrite() public method

Executes multiple write operations.
public bulkWrite ( string $collectionName, array $operations, array $options = [] ) : MongoDB\BulkWriteResult
$collectionName string
$operations array List of write operations
$options array Command options
return MongoDB\BulkWriteResult

command() public method

Execute a command on this database.
public command ( array | object $command, array $options = [] ) : MongoDB\Driver\Cursor
$command array | object Command document
$options array Options for command execution
return MongoDB\Driver\Cursor

connect() public method

Connect to Mongo instance
public connect ( $uri, array $uriOptions = [], array $driverOptions = [] ) : mixed
$uri
$uriOptions array
$driverOptions array
return mixed

count() public method

Gets the number of documents matching the filter.
public count ( string $collectionName, array | object $filter = [], array $options = [] ) : integer
$collectionName string
$filter array | object Query by which to filter documents
$options array Command options
return integer

createCollection() public method

Create collection.
public createCollection ( string $collectionName, array $options = [] ) : array | object
$collectionName string
$options array Additional options
return array | object Command result document

createIndex() public method

Create a single index for the collection.
public createIndex ( string $collectionName, array | object $key, array $options = [] ) : string
$collectionName 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 ( string $collectionName, array $indexes ) : string[]
$collectionName string
$indexes array List of index specifications
return string[] The names of the created indexes

delete() public method

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

distinct() public method

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

dropCollection() public method

Drop this collection.
public dropCollection ( string $collectionName, array $options = [] ) : array | object
$collectionName string
$options array Additional options
return array | object Command result document

dropIndex() public method

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

dropIndexes() public method

Drop all indexes in the collection.
public dropIndexes ( string $collectionName, array $options = [] ) : array | object
$collectionName string
$options array Additional options
return array | object Command result document

find() public method

Finds documents matching the query.
See also: http://docs.mongodb.org/manual/core/read-operations-introduction/
public find ( string $collectionName, array | object $filter = [], array $options = [] ) : MongoDB\Driver\Cursor
$collectionName string
$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: http://docs.mongodb.org/manual/core/read-operations-introduction/
public findOne ( string $collectionName, array | object $filter = [], array $options = [] ) : object | null
$collectionName string
$filter array | object Query by which to filter documents
$options array Additional options
return object | null

findOneAndDelete() public method

The document to return may be null. 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: http://docs.mongodb.org/manual/reference/command/findAndModify/
public findOneAndDelete ( string $collectionName, array | object $filter, array $options = [] ) : object | null
$collectionName string
$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. 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: http://docs.mongodb.org/manual/reference/command/findAndModify/
public findOneAndReplace ( string $collectionName, array | object $filter, array | object $replacement, array $options = [] ) : object | null
$collectionName string
$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. 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: http://docs.mongodb.org/manual/reference/command/findAndModify/
public findOneAndUpdate ( string $collectionName, array | object $filter, array | object $update, array $options = [] ) : object | null
$collectionName string
$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

getNamespace() public method

Return the collection namespace.
See also: http://docs.mongodb.org/manual/faq/developers/#faq-dev-namespace
public getNamespace ( string $collectionName ) : string
$collectionName string
return string

id() public method

Create a mongo ID instance
public id ( null | string $id = null ) : mixed
$id null | string
return mixed

insertMany() public method

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

insertOne() public method

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

isId() public method

Check if given string/object is a valid mongo ID.
public isId ( mixed $id ) : boolean
$id mixed
return boolean

listCollections() public method

Returns information for all collections.
public listCollections ( array $options = [] ) : mixed
$options array
return mixed

listIndexes() public method

Returns information for all indexes for the collection.
public listIndexes ( string $collectionName, array $options = [] ) : MongoDB\Model\IndexInfoIterator
$collectionName string
$options array
return MongoDB\Model\IndexInfoIterator

selectDatabase() public method

Select database
public selectDatabase ( string $database )
$database string

update() public method

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