3
3
namespace MongoDB ;
4
4
5
5
use MongoDB \Driver \Command ;
6
+ use MongoDB \Driver \Cursor ;
6
7
use MongoDB \Driver \Manager ;
7
8
use MongoDB \Driver \Query ;
8
9
use MongoDB \Driver \ReadPreference ;
9
- use MongoDB \Driver \Result ;
10
10
use MongoDB \Driver \BulkWrite ;
11
11
use MongoDB \Driver \WriteConcern ;
12
12
@@ -86,14 +86,16 @@ public function aggregate(array $pipeline, array $options = array())
86
86
"pipeline " => $ pipeline ,
87
87
) + $ options ;
88
88
89
- $ result = $ this ->_runCommand ($ this ->dbname , $ cmd );
90
- $ doc = $ result -> toArray ();
89
+ $ cursor = $ this ->_runCommand ($ this ->dbname , $ cmd );
90
+
91
91
if (isset ($ cmd ["cursor " ]) && $ cmd ["cursor " ]) {
92
- return $ result ;
93
- } else {
94
- if ($ doc ["ok " ]) {
95
- return new \ArrayIterator ($ doc ["result " ]);
96
- }
92
+ return $ cursor ;
93
+ }
94
+
95
+ $ doc = current ($ cursor ->toArray ());
96
+
97
+ if ($ doc ["ok " ]) {
98
+ return new \ArrayIterator ($ doc ["result " ]);
97
99
}
98
100
99
101
throw $ this ->_generateCommandException ($ doc );
@@ -234,7 +236,7 @@ public function count(array $filter = array(), array $options = array())
234
236
"query " => $ filter ,
235
237
) + $ options ;
236
238
237
- $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray ();
239
+ $ doc = current ( $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray () );
238
240
if ($ doc ["ok " ]) {
239
241
return $ doc ["n " ];
240
242
}
@@ -324,7 +326,7 @@ public function distinct($fieldName, array $filter = array(), array $options = a
324
326
"query " => $ filter ,
325
327
) + $ options ;
326
328
327
- $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray ();
329
+ $ doc = current ( $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray () );
328
330
if ($ doc ["ok " ]) {
329
331
return $ doc ["values " ];
330
332
}
@@ -335,7 +337,7 @@ public function distinct($fieldName, array $filter = array(), array $options = a
335
337
* Drop this collection.
336
338
*
337
339
* @see http://docs.mongodb.org/manual/reference/command/drop/
338
- * @return Result
340
+ * @return Cursor
339
341
*/
340
342
public function drop ()
341
343
{
@@ -351,7 +353,7 @@ public function drop()
351
353
* @see http://docs.mongodb.org/manual/reference/command/dropIndexes/
352
354
* @see http://docs.mongodb.org/manual/reference/method/db.collection.dropIndex/
353
355
* @param string $indexName
354
- * @return Result
356
+ * @return Cursor
355
357
* @throws InvalidArgumentException if "*" is specified
356
358
*/
357
359
public function dropIndex ($ indexName )
@@ -364,7 +366,7 @@ public function dropIndex($indexName)
364
366
*
365
367
* @see http://docs.mongodb.org/manual/reference/command/dropIndexes/
366
368
* @see http://docs.mongodb.org/manual/reference/method/db.collection.dropIndexes/
367
- * @return Result
369
+ * @return Cursor
368
370
*/
369
371
public function dropIndexes ()
370
372
{
@@ -379,7 +381,7 @@ public function dropIndexes()
379
381
*
380
382
* @param array $filter The find query to execute
381
383
* @param array $options Additional options
382
- * @return Result
384
+ * @return Cursor
383
385
*/
384
386
public function find (array $ filter = array (), array $ options = array ())
385
387
{
@@ -437,7 +439,7 @@ public function findOneAndDelete(array $filter, array $options = array())
437
439
"query " => $ filter ,
438
440
) + $ options ;
439
441
440
- $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray ();
442
+ $ doc = current ( $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray () );
441
443
if ($ doc ["ok " ]) {
442
444
return $ doc ["value " ];
443
445
}
@@ -474,7 +476,7 @@ public function findOneAndReplace(array $filter, array $replacement, array $opti
474
476
"query " => $ filter ,
475
477
) + $ options ;
476
478
477
- $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray ();
479
+ $ doc = current ( $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray () );
478
480
if ($ doc ["ok " ]) {
479
481
return $ doc ["value " ];
480
482
}
@@ -512,7 +514,7 @@ public function findOneAndUpdate(array $filter, array $update, array $options =
512
514
"query " => $ filter ,
513
515
) + $ options ;
514
516
515
- $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray ();
517
+ $ doc = current ( $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray () );
516
518
if ($ doc ["ok " ]) {
517
519
return $ doc ["value " ];
518
520
}
@@ -951,7 +953,7 @@ public function insertOne(array $document)
951
953
*
952
954
* @see http://docs.mongodb.org/manual/reference/command/listIndexes/
953
955
* @see http://docs.mongodb.org/manual/reference/method/db.collection.getIndexes/
954
- * @return Result
956
+ * @return Cursor
955
957
*/
956
958
public function listIndexes ()
957
959
{
0 commit comments