Beispiel #1
0
    foreach ($cursor as $document) {
        var_dump($document);
    }
    echo "\n";
} catch (Exception $e) {
    printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
    exit;
}
try {
    $cursor = $collection->find();
    echo "Find all docs, should be 3, verify 1x USA citizen, 2x Icelandic\n";
    foreach ($cursor as $document) {
        var_dump($document);
    }
    echo "\n";
    $result = $collection->distinct("citizen");
    echo "Distinct countries:\n";
    var_dump($result);
    echo "\n";
    echo "aggregate\n";
    $result = $collection->aggregate([['$project' => ["name" => 1, "_id" => 0]]], ["useCursor" => true, "batchSize" => 2]);
    printf("Should be 3 different people\n");
    foreach ($result as $person) {
        var_dump($person);
    }
    echo "\n";
} catch (Exception $e) {
    printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
    exit;
}
try {