Rather than operating on records and record sets, queries against MongoDB will return nested sets
of Document objects. A Document's fields can contain both simple and complex data types
(i.e. arrays) including other Document objects.
After installing MongoDB, you can connect to it as follows:
{{{//app/config/bootstrap/connections.php:
Connections::add('default', array('type' => 'MongoDb', 'database' => 'myDb'));}}}
By default, it will attempt to connect to a Mongo instance running on localhost on port
27017. See __construct() for details on the accepted configuration settings.
/** * Hack for embedded data */ public function read($query, array $options = array()) { if (!empty($options['embeddedData'])) { $params = compact('query', 'options'); return $this->_filter(__METHOD__, $params, function ($self, $params) { return $params['options']['embeddedData']; }); } return parent::read($query, $options); }
public function read($query, array $options = array()) { if (!empty($options['data'])) { $params = compact('query', 'options'); $_config = $this->_config; return $this->_filter(__METHOD__, $params, function ($self, $params) use($_config) { $query = $params['query']; $config = compact('query') + array('class' => 'set'); return $self->item($params['query']->model(), $params['options']['data'], $config); }); } return parent::read($query, $options); }
public function skip() { $this->skipIf(!MongoDb::enabled(), 'MongoDb is not enabled'); $this->skipIf(!CouchDb::enabled(), 'CouchDb is not enabled'); }
public function testEnabled() { $this->assertTrue(MongoDb::enabled()); }
public function testArrayConversion() { $this->skipIf(!MongoDb::enabled(), "MongoDB not enabled, skipping conversion tests."); $time = time(); $doc = new Document(array('data' => array('_id' => new MongoId(), 'date' => new MongoDate($time)))); $result = $doc->data(); $this->assertPattern('/^[a-f0-9]{24}$/', $result['_id']); $this->assertEqual($time, $result['date']); }
public function testRespondsToWithServer() { $db = new MongoDb($this->_testConfig); $db->server = new MockMongoConnection(); $this->assertTrue($db->respondsTo('listDBs')); $this->assertFalse($db->respondsTo('foobarbaz')); }
public function testSchemaCallback() { $schema = array('_id' => array('type' => 'id'), 'created' => array('type' => 'date')); $db = new MongoDb(array('autoConnect' => false, 'schema' => function () use($schema) { return $schema; })); $this->assertEqual($schema, $db->describe(null)); }
public function testEnabled() { $this->assertTrue(MongoDb::enabled()); $this->assertTrue(MongoDb::enabled('arrays')); $this->assertTrue(MongoDb::enabled('booleans')); $this->assertTrue(MongoDb::enabled('relationships')); }
public function __construct($connection) { parent::__construct(array('autoConnect' => false)); $this->connection = $connection->connection; $this->_isConnected = true; }