Class: MongoManager

Class to manage the connection to a MongoDB database. To specify your MongoDB settings, add the following section to conf/config.php:

[Mongo]
host = localhost:27017
name = database_name
user = username ; optional
pass = password ; optional
set_name = my_replica_set ; optional

Then you can either use this class directly like so:

<?php

// get the connection
$mongo = MongoManager::get_connection ();

// get the MongoDbB object
$db = MongoManager::get_database ();

?>

Or use the MongoModel class to define a Mongo-based model for your data:

<?php

class MyCollection extends MongoModel {}

$obj = new MyCollection (array ('foo' => 'bar'));
$obj->put ();
// etc.

?>

Properties

public static $conn = false

The Mongo connection object.

public static $error = false

The error string if a connection error occurred.

Methods

public static get_connection ()

Get the Mongo database connection object. Uses your settings from conf/config.php for the connection info (host, name, user, pass, and set_name). The host and database name are required, but authentication (user and pass) settings and replica set name (set_name) are optional.

public static get_database ()

Get the MongoDB database object.