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.
See also: lithium\data\entity\Document
See also: lithium\data\Connections::add()
See also: lithium\data\source\MongoDb::__construct()
Inheritance: extends lithium\data\Source
 /**
  * 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);
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 public function skip()
 {
     $this->skipIf(!MongoDb::enabled(), 'MongoDb is not enabled');
     $this->skipIf(!CouchDb::enabled(), 'CouchDb is not enabled');
 }
Ejemplo n.º 4
0
 public function testEnabled()
 {
     $this->assertTrue(MongoDb::enabled());
 }
Ejemplo n.º 5
0
 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']);
 }
Ejemplo n.º 6
0
 public function testRespondsToWithServer()
 {
     $db = new MongoDb($this->_testConfig);
     $db->server = new MockMongoConnection();
     $this->assertTrue($db->respondsTo('listDBs'));
     $this->assertFalse($db->respondsTo('foobarbaz'));
 }
Ejemplo n.º 7
0
 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));
 }
Ejemplo n.º 8
0
 public function testEnabled()
 {
     $this->assertTrue(MongoDb::enabled());
     $this->assertTrue(MongoDb::enabled('arrays'));
     $this->assertTrue(MongoDb::enabled('booleans'));
     $this->assertTrue(MongoDb::enabled('relationships'));
 }
Ejemplo n.º 9
0
 public function __construct($connection)
 {
     parent::__construct(array('autoConnect' => false));
     $this->connection = $connection->connection;
     $this->_isConnected = true;
 }