PHP Class MongoDB

Datei anzeigen Open project: alcaeus/mongo-php-adapter Class Usage Examples

Protected Properties

Property Type Description
$connection MongoClient
$db MongoDB\Database
$name string

Public Methods

Method Description
__construct ( MongoClient $conn, string $name ) Creates a new database
__get ( string $name ) : MongoCollection Gets a collection
__set ( string $name, mixed $value )
__sleep ( ) : array
__toString ( ) : string The name of this database
authenticate ( string $username, string $password ) : array Log in to this database
command ( array $data, array $options = [], &$hash = null ) : array Execute a database command
createCollection ( string $name, array $options ) : MongoCollection Creates a collection
createDBRef ( string $collection, mixed $document_or_id ) : array Creates a database reference
drop ( ) : array Drops this database
dropCollection ( MongoCollection | string $coll ) : array Drops a collection
execute ( MongoCode | string $code, array $args = [] ) : array Runs JavaScript code on the database server.
forceError ( ) : boolean Creates a database error
getCollectionInfo ( array $options = [] ) : array Returns information about collections in this database
getCollectionNames ( array $options = [] ) : array Get all collections from this database
getConnection ( ) : MongoClient
getDBRef ( array $ref ) : array Fetches the document pointed to by a database reference
getDb ( ) : MongoDB\Database
getGridFS ( string $prefix = "fs" ) : MongoGridFS Fetches toolkit for dealing with files stored in this database
getProfilingLevel ( ) : integer Gets this database's profiling level
lastError ( ) : array Check if there was an error on the most recent db operation performed
listCollections ( array $options = [] ) : MongoCollection[] Get a list of collections in this database
prevError ( ) : array Checks for the last error thrown during a database operation
repair ( boolean $preserve_cloned_files = FALSE, boolean $backup_original_files = FALSE ) : array Repairs and compacts this database
resetError ( ) : array Clears any flagged errors on the database
selectCollection ( string $name ) : MongoCollection Gets a collection
setProfilingLevel ( integer $level ) : integer Sets this database's profiling level
setReadPreference ( $readPreference, $tags = null )
setWriteConcern ( $wstring, $wtimeout )

Protected Methods

Method Description
notImplemented ( )

Private Methods

Method Description
checkDatabaseName ( $name )
createDatabaseObject ( ) : MongoDB\Database
getSystemCollectionFilterClosure ( boolean $includeSystemCollections = false ) : Closure

Method Details

__construct() public method

This method is not meant to be called directly. The preferred way to create an instance of MongoDB is through {@see \Mongo::__get()} or {@see \Mongo::selectDB()}.
public __construct ( MongoClient $conn, string $name )
$conn MongoClient Database connection.
$name string Database name.

__get() public method

Gets a collection
public __get ( string $name ) : MongoCollection
$name string The name of the collection.
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

The name of this database
public __toString ( ) : string
return string Returns this database's name.

authenticate() public method

Log in to this database
Deprecation: This method is not implemented, supply authentication credentials through the connection string instead.
public authenticate ( string $username, string $password ) : array
$username string The username.
$password string The password (in plaintext).
return array Returns database response. If the login was successful, it will return 1.

command() public method

Execute a database command
public command ( array $data, array $options = [], &$hash = null ) : array
$data array The query to send.
$options array
return array Returns database response.

createCollection() public method

Creates a collection
public createCollection ( string $name, array $options ) : MongoCollection
$name string The name of the collection.
$options array
return MongoCollection Returns a collection object representing the new collection.

createDBRef() public method

Creates a database reference
public createDBRef ( string $collection, mixed $document_or_id ) : array
$collection string The collection to which the database reference will point.
$document_or_id mixed
return array Returns a database reference array.

drop() public method

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

dropCollection() public method

Drops a collection
Deprecation: Use MongoCollection::drop() instead.
public dropCollection ( MongoCollection | string $coll ) : array
$coll MongoCollection | string MongoCollection or name of collection to drop.
return array Returns the database response.

execute() public method

Runs JavaScript code on the database server.
public execute ( MongoCode | string $code, array $args = [] ) : array
$code MongoCode | string Code to execute.
$args array [optional] Arguments to be passed to code.
return array Returns the result of the evaluation.

forceError() public method

Creates a database error
public forceError ( ) : boolean
return boolean Returns the database response.

getCollectionInfo() public method

Returns information about collections in this database
public getCollectionInfo ( array $options = [] ) : array
$options array An array of options for listing the collections.
return array

getCollectionNames() public method

Get all collections from this database
public getCollectionNames ( array $options = [] ) : array
$options array An array of options for listing the collections.
return array Returns the names of the all the collections in the database as an array

getConnection() public method

public getConnection ( ) : MongoClient
return MongoClient

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 document pointed to by the reference.

getDb() public method

public getDb ( ) : MongoDB\Database
return MongoDB\Database

getGridFS() public method

Fetches toolkit for dealing with files stored in this database
public getGridFS ( string $prefix = "fs" ) : MongoGridFS
$prefix string The prefix for the files and chunks collections.
return MongoGridFS Returns a new gridfs object for this database.

getProfilingLevel() public method

Gets this database's profiling level
public getProfilingLevel ( ) : integer
return integer Returns the profiling level.

lastError() public method

Check if there was an error on the most recent db operation performed
public lastError ( ) : array
return array Returns the error, if there was one.

listCollections() public method

Get a list of collections in this database
public listCollections ( array $options = [] ) : MongoCollection[]
$options array
return MongoCollection[] Returns a list of MongoCollections.

notImplemented() protected method

protected notImplemented ( )

prevError() public method

Checks for the last error thrown during a database operation
public prevError ( ) : array
return array Returns the error and the number of operations ago it occurred.

repair() public method

Repairs and compacts this database
public repair ( boolean $preserve_cloned_files = FALSE, boolean $backup_original_files = FALSE ) : array
$preserve_cloned_files boolean [optional]

If cloned files should be kept if the repair fails.

$backup_original_files boolean [optional]

If original files should be backed up.

return array

Returns db response.

resetError() public method

Clears any flagged errors on the database
public resetError ( ) : array
return array Returns the database response.

selectCollection() public method

Gets a collection
public selectCollection ( string $name ) : MongoCollection
$name string The collection name.
return MongoCollection Returns a new collection object.

setProfilingLevel() public method

Sets this database's profiling level
public setProfilingLevel ( integer $level ) : integer
$level integer Profiling level.
return integer Returns the previous profiling level.

setReadPreference() public method

public setReadPreference ( $readPreference, $tags = null )

setWriteConcern() public method

public setWriteConcern ( $wstring, $wtimeout )

Property Details

$connection protected_oe property

protected MongoClient $connection
return MongoClient

$db protected_oe property

protected Database,MongoDB $db
return MongoDB\Database

$name protected_oe property

protected string $name
return string