xtfer/vultan

A lightweight MongoDB wrapper

Installs: 13

Dependents: 0

Stars: 1

Language: PHP

0.1.2-alpha 2014-03-05 11:12 UTC

README

Vultan wraps the native MongoPHP driver and provides a fluent, extensible query interface.

Insert a document

// Using the connect() method without arguments returns a connection to the
// default MongoDB on localhost.
$vultan = \Vultan\Vultan::connect();

// Choose a database.
$vultan->useDatabase('cars');

// Choose a collection to work with.
$vultan->useCollection('marques');

// Prepare some data.
$data = array(
  'name' => 'Rolls Royce',
  'founded' => '1906',
  'type' => 'manufacturer',
  'place' => 'Manchester'
);

// Insert some data.
$result = $vultan->insert($data)->execute();

Find a document

$vultan = \Vultan\Vultan::connect()
  ->useDatabase('cars')
  ->useCollection('marques');

$query = $vultan->find();

$result_data = $query
  // Add some conditions.
  ->addCondition('founded', '1906')
  ->addCondition('place', 'Manchester')
  // Ensure the query returns an array. Omit this if you prefer an iterator.
  ->resultsAsArray()
  // Run the query.
  ->execute();

print_r($result_data);