All pastes #2071829 Raw Edit

Anonymous

public text v1 · immutable
#2071829 ·published 2011-05-30 04:36 UTC
rendered paste body
<?php
/**
 * @file
 * webchick's adventures with MongoDB!
 *
 * Useful resources:
 * - http://ca2.php.net/manual/en/mongo.tutorial.php
 * - http://groups.google.com/group/mongodb-user/browse_thread/thread/443d91dcb1220206/a3cc0d
1d8bb0da78
 */

// Connect using default parameters (localhost:27017, no user/pass).
$m = new Mongo();

// Show all available databases.
$db = $m->selectDB("admin");
$dbList = $db->command(array("listDatabases" => 1));

// Describe the collections (tables) on each database.
foreach ($dbList['databases'] as $name) {
  $db = $m->selectDB($name['name']);
  var_dump("Database: {$name['name']}");
  $list = $db->listCollections();

  // Loop through each collection and provide schema information.
  foreach ($list as $collection) {
    var_dump("Collection: {$collection->getName()}");

    $cursor = $collection->findOne();
    foreach ($cursor as $obj) {
      var_dump($obj);
    }
  }
}