Skip to content

Commit b42502f

Browse files
author
Jan Steemann
committed
added data export example
1 parent 84c8adc commit b42502f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ $export = new ArangoExport($connection, 'users', array());
514514
$cursor = $export->execute();
515515

516516
// now we can fetch the documents from the collection in blocks
517-
while ($docs = $export->getNextBatch()) {
517+
while ($docs = $cursor->getNextBatch()) {
518518
// do something with $docs
519519
var_dump($docs);
520520
}

examples/export.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace triagens\ArangoDb;
4+
5+
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php';
6+
7+
try {
8+
$connection = new Connection($connectionOptions);
9+
10+
// creates an export object for collection 'users'
11+
$export = new Export($connection, 'users', array(
12+
"batchSize" => 5000,
13+
"_flat" => true,
14+
"flush" => true,
15+
"restrict" => array(
16+
"type" => "include",
17+
"fields" => array("_key", "_rev")
18+
)
19+
));
20+
21+
// execute the export. this will return a special, forward-only cursor
22+
$cursor = $export->execute();
23+
24+
// now we can fetch the documents from the collection in blocks
25+
while ($docs = $cursor->getNextBatch()) {
26+
// do something with $docs
27+
print sprintf("retrieved %d documents", count($docs)) . PHP_EOL;
28+
}
29+
30+
} catch (ConnectException $e) {
31+
print $e . PHP_EOL;
32+
} catch (ServerException $e) {
33+
print $e . PHP_EOL;
34+
} catch (ClientException $e) {
35+
print $e . PHP_EOL;
36+
}

0 commit comments

Comments
 (0)