/** * {@inheritdoc} */ public function preFlight() { $this->vultan = Vultan::connect()->useDatabase('test')->useCollection('test'); }
<?php /** * @file * Document example. */ // Simply loads the Composer Autoloader. require './../../vendor/autoload.php'; $vultan = \Vultan\Vultan::connect(); // The DocumentFactory is designed for handling dependency injection for // Document creation. // // Documents can be created empty. $document = $vultan->getDocumentFactory()->createDocument(); // Or documents can have data in them. $my_data = array('some_key' => 'apple', 'another_key' => 'orange'); $document = $vultan->getDocumentFactory()->createDocument($my_data); // Non-modelled documents must provide their collection. $document->setCollection('fruit'); // We can perform an Upsert on the object directly. $document->save(); // Using the same vultan object, we can do a query to see our insert. // Note that we'll need to set the collection explicitly this time. $vultan->useCollection('fruit'); $result = $vultan->findAll(array('some_key' => 'apple')); print '<pre>'; print_r($result); print '</pre>';
<?php /** * @file * Provides an example for updating data. */ // Simply loads the Composer Autoloader. require '../vendor/autoload.php'; // Using the connect() method without arguments returns a connection to the // default MongoDB on localhost. $vultan = \Vultan\Vultan::connect()->useDatabase('cars')->useCollection('marques'); /* * Update the first matched item. */ // We now have two records, this will only update one. $data = array('name' => 'Rolls Royce', 'founded' => '1906', 'place' => 'Manchester', 'type' => 'manufacturer'); $filter = array('name' => 'Rolls Royce'); $result = $vultan->update($data, $filter)->execute(); // Message... // Print a useful message. print '<h2>First update result:</h2>'; print '<p>' . $result->getMessage() . '</p>'; /* * Update all matched items. */ // There are still two records, however they are now different. We'll do a // partial update on both. This will update only the field specified. $filter = array('type' => 'manufacturer'); $data = array('founded' => '1900'); $result = $vultan->updateAll($data, $filter, TRUE)->execute(); // Print a useful message.