File tree Expand file tree Collapse file tree 2 files changed +108
-0
lines changed Expand file tree Collapse file tree 2 files changed +108
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ MongoDB\Driver\Cursor query result shared by multiple iterators
3
+ --SKIPIF--
4
+ <?php require __DIR__ . "/../utils/basic-skipif.inc " ; CLEANUP (STANDALONE ) ?>
5
+ --FILE--
6
+ <?php
7
+ require_once __DIR__ . "/../utils/basic.inc " ;
8
+
9
+ $ manager = new MongoDB \Driver \Manager (STANDALONE );
10
+
11
+ $ bulkWrite = new MongoDB \Driver \BulkWrite ;
12
+
13
+ for ($ i = 0 ; $ i < 8 ; $ i ++) {
14
+ $ bulkWrite ->insert (array ('_id ' => $ i ));
15
+ }
16
+
17
+ $ writeResult = $ manager ->executeBulkWrite (NS , $ bulkWrite );
18
+ printf ("Inserted: %d \n" , $ writeResult ->getInsertedCount ());
19
+
20
+ $ cursor = $ manager ->executeQuery (NS , new MongoDB \Driver \Query (array ()));
21
+
22
+ foreach ($ cursor as $ i => $ document ) {
23
+ printf ("A: %d => {_id: %d} \n" , $ i , $ document ['_id ' ]);
24
+
25
+ if ($ i == 2 ) {
26
+ foreach ($ cursor as $ j => $ document ) {
27
+ printf ("B: %d => {_id: %d} \n" , $ j , $ document ['_id ' ]);
28
+
29
+ if ($ j == 2 ) {
30
+ break ;
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ ?>
37
+ ===DONE===
38
+ <?php exit (0 ); ?>
39
+ --EXPECT--
40
+ Inserted: 8
41
+ A: 0 => {_id: 0}
42
+ A: 1 => {_id: 1}
43
+ A: 2 => {_id: 2}
44
+ B: 0 => {_id: 2}
45
+ B: 1 => {_id: 3}
46
+ B: 2 => {_id: 4}
47
+ A: 3 => {_id: 5}
48
+ A: 4 => {_id: 6}
49
+ A: 5 => {_id: 7}
50
+ ===DONE===
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ MongoDB\Driver\Cursor command result shared by multiple iterators
3
+ --SKIPIF--
4
+ <?php require __DIR__ . "/../utils/basic-skipif.inc " ; CLEANUP (STANDALONE ) ?>
5
+ --FILE--
6
+ <?php
7
+ require_once __DIR__ . "/../utils/basic.inc " ;
8
+
9
+ $ manager = new MongoDB \Driver \Manager (STANDALONE );
10
+
11
+ $ bulkWrite = new MongoDB \Driver \BulkWrite ;
12
+
13
+ for ($ i = 0 ; $ i < 8 ; $ i ++) {
14
+ $ bulkWrite ->insert (array ('_id ' => $ i ));
15
+ }
16
+
17
+ $ writeResult = $ manager ->executeBulkWrite (NS , $ bulkWrite );
18
+ printf ("Inserted: %d \n" , $ writeResult ->getInsertedCount ());
19
+
20
+ $ command = new MongoDB \Driver \Command (array (
21
+ 'aggregate ' => COLLECTION_NAME ,
22
+ 'pipeline ' => array (
23
+ array ('$match ' => new stdClass ),
24
+ ),
25
+ 'cursor ' => new stdClass ,
26
+ ));
27
+
28
+ $ cursor = $ manager ->executeCommand (DATABASE_NAME , $ command );
29
+
30
+ foreach ($ cursor as $ i => $ document ) {
31
+ printf ("A: %d => {_id: %d} \n" , $ i , $ document ['_id ' ]);
32
+
33
+ if ($ i == 2 ) {
34
+ foreach ($ cursor as $ j => $ document ) {
35
+ printf ("B: %d => {_id: %d} \n" , $ j , $ document ['_id ' ]);
36
+
37
+ if ($ j == 2 ) {
38
+ break ;
39
+ }
40
+ }
41
+ }
42
+ }
43
+
44
+ ?>
45
+ ===DONE===
46
+ <?php exit (0 ); ?>
47
+ --EXPECT--
48
+ Inserted: 8
49
+ A: 0 => {_id: 0}
50
+ A: 1 => {_id: 1}
51
+ A: 2 => {_id: 2}
52
+ B: 0 => {_id: 2}
53
+ B: 1 => {_id: 3}
54
+ B: 2 => {_id: 4}
55
+ A: 3 => {_id: 5}
56
+ A: 4 => {_id: 6}
57
+ A: 5 => {_id: 7}
58
+ ===DONE===
You can’t perform that action at this time.
0 commit comments