Beispiel #1
0
/**
 * Deletes all our known collections
 * 
 * @param MongoDB $db
 */
function zapDatabase(MongoDB $db)
{
    getComponentCollection($db)->drop();
    getManufacturerCollection($db)->drop();
}
Beispiel #2
0
$m = new MongoClient();
// select a database and clear it
$db = $m->bikes;
zapDatabase($db);
// Let's create some component manufacturers
$manuCollection = getManufacturerCollection($db);
createManufacturer($manuCollection, "Haibike");
// Of the bike itself
createManufacturer($manuCollection, "Yamaha");
// Component manufacturers
createManufacturer($manuCollection, "Shimano");
createManufacturer($manuCollection, "Fox");
createManufacturer($manuCollection, "Selle Royal");
createManufacturer($manuCollection, "FSA");
// Let's create some components
$compCollection = getComponentCollection($db);
$ids = [];
$ids[] = createDocument($compCollection, "Battery 400Wh", ['watt-hours' => 400]);
$ids[] = createDocument($compCollection, "Motor", ['voltage' => 36, 'wattage' => 250, 'manufacturer' => getManufacturerId($manuCollection, 'yamaha'), 'list_price' => ['currency' => 'GBP', 'value' => 300]]);
$ids[] = createDocument($compCollection, "Haibike SDURO frame", ['material' => 'Aluminium', 'size_inches' => 27.5, 'description' => "6061, All MNT, 4-Link System, Yamaha-Interface, hydroforced tubes, 150mm", 'list_price' => ['currency' => 'GBP', 'value' => 400]]);
// Special group for the drivetrain
$dtIds = [];
$dtIds[] = createDocument($compCollection, 'Haibike sDuro crank', ['material' => 'Aluminium', 'gears' => 2, 'list_price' => ['currency' => 'GBP', 'value' => 45]]);
$dtIds[] = createDocument($compCollection, 'Front Derailleur', ['manufacturer' => getManufacturerId($manuCollection, 'shimano'), 'list_price' => ['currency' => 'GBP', 'value' => 40]]);
$dtIds[] = createDocument($compCollection, "Rear Derailleur", ['manufacturer' => getManufacturerId($manuCollection, 'shimano'), 'line' => 'Deore XT', 'model' => 'M 786 Shadow Plus', 'gears' => 10, 'list_price' => ['currency' => 'GBP', 'value' => 50]]);
$dtIds[] = createDocument($compCollection, "Cassette", ['description' => 'Sram PG 1020 11-36 Teeth', 'list_price' => ['currency' => 'GBP', 'value' => 60]]);
// Finally put the drivetrain together
$ids[] = createDocument($compCollection, "Haibike SDURO Drivetrain", ['speeds' => 20, 'components' => createIdsGroup($dtIds)]);
// Let's create a full bike
createDocument($compCollection, "Haibike SDURO AllMtn RC", ['full_build' => true, 'components' => createIdsGroup($ids)]);
// Show the full builds, which include all of the above components