1
1
<?php
2
+
2
3
namespace MongoDB ;
3
4
4
- /* {{{ phongo includes */
5
- use MongoDB \Manager ;
6
- use MongoDB \Query ;
7
- use MongoDB \Command ;
8
- use MongoDB \ReadPreference ;
9
- use MongoDB \WriteBatch ;
10
- /* }}} */
5
+ use MongoDB \ Driver \ Command ;
6
+ use MongoDB \Driver \ Manager ;
7
+ use MongoDB \Driver \ Query ;
8
+ use MongoDB \Driver \ ReadPreference ;
9
+ use MongoDB \Driver \ Result ;
10
+ use MongoDB \Driver \ WriteBatch ;
11
+ use MongoDB \ Driver \ WriteConcern ;
11
12
12
13
class Collection
13
14
{
@@ -42,15 +43,15 @@ class Collection
42
43
43
44
44
45
/**
45
- * Constructs new MongoDB\ Collection instance
46
+ * Constructs new Collection instance
46
47
*
47
48
* This is the suggested CRUD interface when using phongo.
48
49
* It implements the MongoDB CRUD specification which is an interface all MongoDB
49
50
* supported drivers follow.
50
51
*
51
- * @param MongoDB\ Manager $manager The phongo Manager instance
52
- * @param MongoDB\ WriteConcern $wc The WriteConcern to apply to writes
53
- * @param MongoDB\ ReadPreference $rp The ReadPreferences to apply to reads
52
+ * @param Manager $manager The phongo Manager instance
53
+ * @param WriteConcern $wc The WriteConcern to apply to writes
54
+ * @param ReadPreference $rp The ReadPreferences to apply to reads
54
55
*/
55
56
public function __construct (Manager $ manager , $ ns , WriteConcern $ wc = null , ReadPreference $ rp = null )
56
57
{
@@ -66,11 +67,11 @@ public function __construct(Manager $manager, $ns, WriteConcern $wc = null, Read
66
67
* Performs a find (query) on the collection
67
68
*
68
69
* @see http://docs.mongodb.org/manual/core/read-operations-introduction/
69
- * @see MongoDB\ Collection::getFindOptions() for supported $options
70
+ * @see Collection::getFindOptions() for supported $options
70
71
*
71
72
* @param array $filter The find query to execute
72
73
* @param array $options Additional options
73
- * @return MongoDB\QueryResult
74
+ * @return Result
74
75
*/
75
76
public function find (array $ filter = array (), array $ options = array ())
76
77
{
@@ -87,7 +88,7 @@ public function find(array $filter = array(), array $options = array())
87
88
* Performs a find (query) on the collection, returning at most one result
88
89
*
89
90
* @see http://docs.mongodb.org/manual/core/read-operations-introduction/
90
- * @see MongoDB\ Collection::getFindOptions() for supported $options
91
+ * @see Collection::getFindOptions() for supported $options
91
92
*
92
93
* @param array $filter The find query to execute
93
94
* @param array $options Additional options
@@ -112,7 +113,7 @@ public function findOne(array $filter = array(), array $options = array())
112
113
/**
113
114
* Retrieves all find options with their default values.
114
115
*
115
- * @return array of MongoDB\ Collection::find() options
116
+ * @return array of Collection::find() options
116
117
*/
117
118
public function getFindOptions ()
118
119
{
@@ -142,9 +143,8 @@ public function getFindOptions()
142
143
/**
143
144
* Indicates the type of cursor to use. This value includes both
144
145
* the tailable and awaitData options.
145
- * The default is MongoDB\self ::CURSOR_TYPE_NON_TAILABLE.
146
+ * The default is Collection ::CURSOR_TYPE_NON_TAILABLE.
146
147
*
147
- * @see MongoDB\CursorType
148
148
* @see http://docs.mongodb.org/manual/reference/operator/meta/comment/
149
149
*/
150
150
"cursorType " => self ::CURSOR_TYPE_NON_TAILABLE ,
@@ -232,11 +232,11 @@ final protected function _opQueryFlags($options)
232
232
}
233
233
234
234
/**
235
- * Helper to build a MongoDB\ Query object
235
+ * Helper to build a Query object
236
236
*
237
237
* @param array $filter the query document
238
238
* @param array $options query/protocol options
239
- * @return MongoDB\ Query
239
+ * @return Query
240
240
* @internal
241
241
*/
242
242
final protected function _buildQuery ($ filter , $ options )
@@ -312,26 +312,26 @@ public function getBulkOptions()
312
312
* - 'insertOne'
313
313
* Supports no $extraArgument
314
314
* - 'updateMany'
315
- * Requires $extraArgument1, same as $update for MongoDB\ Collection\ updateMany()
316
- * Optional $extraArgument2, same as $options for MongoDB\ Collection\ updateMany()
315
+ * Requires $extraArgument1, same as $update for Collection:: updateMany()
316
+ * Optional $extraArgument2, same as $options for Collection:: updateMany()
317
317
* - 'updateOne'
318
- * Requires $extraArgument1, same as $update for MongoDB\ Collection\ updateOne()
319
- * Optional $extraArgument2, same as $options for MongoDB\ Collection\ updateOne()
318
+ * Requires $extraArgument1, same as $update for Collection:: updateOne()
319
+ * Optional $extraArgument2, same as $options for Collection:: updateOne()
320
320
* - 'replaceOne'
321
- * Requires $extraArgument1, same as $update for MongoDB\ Collection\ replaceOne()
322
- * Optional $extraArgument2, same as $options for MongoDB\ Collection\ replaceOne()
321
+ * Requires $extraArgument1, same as $update for Collection:: replaceOne()
322
+ * Optional $extraArgument2, same as $options for Collection:: replaceOne()
323
323
* - 'deleteOne'
324
324
* Supports no $extraArgument
325
325
* - 'deleteMany'
326
326
* Supports no $extraArgument
327
327
*
328
328
* @example Collection-bulkWrite.php Using Collection::bulkWrite()
329
329
*
330
- * @see MongoDB\ Collection::getBulkOptions() for supported $options
330
+ * @see Collection::getBulkOptions() for supported $options
331
331
*
332
332
* @param array $bulk Array of operations
333
333
* @param array $options Additional options
334
- * @return MongoDB\ WriteResult
334
+ * @return WriteResult
335
335
*/
336
336
public function bulkWrite (array $ bulk , array $ options = array ())
337
337
{
@@ -405,11 +405,11 @@ public function bulkWrite(array $bulk, array $options = array())
405
405
* Inserts the provided document
406
406
*
407
407
* @see http://docs.mongodb.org/manual/reference/command/insert/
408
- * @see MongoDB\ Collection::getWriteOptions() for supported $options
408
+ * @see Collection::getWriteOptions() for supported $options
409
409
*
410
410
* @param array $document The document to insert
411
411
* @param array $options Additional options
412
- * @return MongoDB\ InsertResult
412
+ * @return InsertResult
413
413
*/
414
414
public function insertOne (array $ document )
415
415
{
@@ -442,7 +442,7 @@ final protected function _delete($filter, $limit = 1)
442
442
* @see http://docs.mongodb.org/manual/reference/command/delete/
443
443
*
444
444
* @param array $filter The $filter criteria to delete
445
- * @return MongoDB\ DeleteResult
445
+ * @return DeleteResult
446
446
*/
447
447
public function deleteOne (array $ filter )
448
448
{
@@ -458,7 +458,7 @@ public function deleteOne(array $filter)
458
458
* @see http://docs.mongodb.org/manual/reference/command/delete/
459
459
*
460
460
* @param array $filter The $filter criteria to delete
461
- * @return MongoDB\ DeleteResult
461
+ * @return DeleteResult
462
462
*/
463
463
public function deleteMany (array $ filter )
464
464
{
@@ -484,12 +484,12 @@ protected function _update($filter, $update, $options)
484
484
* Replace one document
485
485
*
486
486
* @see http://docs.mongodb.org/manual/reference/command/update/
487
- * @see MongoDB\ Collection::getWriteOptions() for supported $options
487
+ * @see Collection::getWriteOptions() for supported $options
488
488
*
489
489
* @param array $filter The document to be replaced
490
490
* @param array $update The document to replace with
491
491
* @param array $options Additional options
492
- * @return MongoDB\ UpdateResult
492
+ * @return UpdateResult
493
493
*/
494
494
public function replaceOne (array $ filter , array $ update , array $ options = array ())
495
495
{
@@ -506,12 +506,12 @@ public function replaceOne(array $filter, array $update, array $options = array(
506
506
* NOTE: Will update at most ONE document matching $filter
507
507
*
508
508
* @see http://docs.mongodb.org/manual/reference/command/update/
509
- * @see MongoDB\ Collection::getWriteOptions() for supported $options
509
+ * @see Collection::getWriteOptions() for supported $options
510
510
*
511
511
* @param array $filter The document to be replaced
512
512
* @param array $update An array of update operators to apply to the document
513
513
* @param array $options Additional options
514
- * @return MongoDB\ UpdateResult
514
+ * @return UpdateResult
515
515
*/
516
516
public function updateOne (array $ filter , array $ update , array $ options = array ())
517
517
{
@@ -528,12 +528,12 @@ public function updateOne(array $filter, array $update, array $options = array()
528
528
* NOTE: Will update ALL documents matching $filter
529
529
*
530
530
* @see http://docs.mongodb.org/manual/reference/command/update/
531
- * @see MongoDB\ Collection::getWriteOptions() for supported $options
531
+ * @see Collection::getWriteOptions() for supported $options
532
532
*
533
533
* @param array $filter The document to be replaced
534
534
* @param array $update An array of update operators to apply to the document
535
535
* @param array $options Additional options
536
- * @return MongoDB\ UpdateResult
536
+ * @return UpdateResult
537
537
*/
538
538
public function updateMany (array $ filter , $ update , array $ options = array ())
539
539
{
@@ -547,7 +547,7 @@ public function updateMany(array $filter, $update, array $options = array())
547
547
* If no $filter provided, returns the numbers of documents in the collection
548
548
*
549
549
* @see http://docs.mongodb.org/manual/reference/command/count/
550
- * @see MongoDB\ Collection::getCountOptions() for supported $options
550
+ * @see Collection::getCountOptions() for supported $options
551
551
*
552
552
* @param array $filter The find query to execute
553
553
* @param array $options Additional options
@@ -560,7 +560,7 @@ public function count(array $filter = array(), array $options = array())
560
560
"query " => $ filter ,
561
561
) + $ options ;
562
562
563
- $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->getResponseDocument ();
563
+ $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray ();
564
564
if ($ doc ["ok " ]) {
565
565
return $ doc ["n " ];
566
566
}
@@ -570,7 +570,7 @@ public function count(array $filter = array(), array $options = array())
570
570
/**
571
571
* Retrieves all count options with their default values.
572
572
*
573
- * @return array of MongoDB\ Collection::count() options
573
+ * @return array of Collection::count() options
574
574
*/
575
575
public function getCountOptions ()
576
576
{
@@ -609,7 +609,7 @@ public function getCountOptions()
609
609
* Finds the distinct values for a specified field across the collection
610
610
*
611
611
* @see http://docs.mongodb.org/manual/reference/command/distinct/
612
- * @see MongoDB\ Collection::getDistinctOptions() for supported $options
612
+ * @see Collection::getDistinctOptions() for supported $options
613
613
*
614
614
* @param string $fieldName The fieldname to use
615
615
* @param array $filter The find query to execute
@@ -625,7 +625,7 @@ public function distinct($fieldName, array $filter = array(), array $options = a
625
625
"query " => $ filter ,
626
626
) + $ options ;
627
627
628
- $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->getResponseDocument ();
628
+ $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray ();
629
629
if ($ doc ["ok " ]) {
630
630
return $ doc ["values " ];
631
631
}
@@ -635,7 +635,7 @@ public function distinct($fieldName, array $filter = array(), array $options = a
635
635
/**
636
636
* Retrieves all distinct options with their default values.
637
637
*
638
- * @return array of MongoDB\ Collection::distinct() options
638
+ * @return array of Collection::distinct() options
639
639
*/
640
640
public function getDistinctOptions ()
641
641
{
@@ -653,15 +653,15 @@ public function getDistinctOptions()
653
653
* Runs an aggregation framework pipeline
654
654
* NOTE: The return value of this method depends on your MongoDB server version
655
655
* and possibly options.
656
- * MongoDB 2.6 (and later) will return a MongoDB\QueryCursor by default
657
- * MongoDB pre 2.6 will return a ArrayIterator
656
+ * MongoDB 2.6 (and later) will return a Cursor by default
657
+ * MongoDB pre 2.6 will return an ArrayIterator
658
658
*
659
659
* @see http://docs.mongodb.org/manual/reference/command/aggregate/
660
- * @see MongoDB\ Collection::getAggregateOptions() for supported $options
660
+ * @see Collection::getAggregateOptions() for supported $options
661
661
*
662
662
* @param array $pipeline The pipeline to execute
663
663
* @param array $options Additional options
664
- * @return Iteratable
664
+ * @return Iterator
665
665
*/
666
666
public function aggregate (array $ pipeline , array $ options = array ())
667
667
{
@@ -673,7 +673,7 @@ public function aggregate(array $pipeline, array $options = array())
673
673
) + $ options ;
674
674
675
675
$ result = $ this ->_runCommand ($ this ->dbname , $ cmd );
676
- $ doc = $ result ->getResponseDocument ();
676
+ $ doc = $ result ->toArray ();
677
677
if (isset ($ cmd ["cursor " ]) && $ cmd ["cursor " ]) {
678
678
return $ result ;
679
679
} else {
@@ -688,7 +688,7 @@ public function aggregate(array $pipeline, array $options = array())
688
688
/**
689
689
* Retrieves all aggregate options with their default values.
690
690
*
691
- * @return array of MongoDB\ Collection::aggregate() options
691
+ * @return array of Collection::aggregate() options
692
692
*/
693
693
public function getAggregateOptions ()
694
694
{
@@ -752,7 +752,7 @@ protected function _massageAggregateOptions($options)
752
752
* Finds a single document and deletes it, returning the original.
753
753
*
754
754
* @see http://docs.mongodb.org/manual/reference/command/findAndModify/
755
- * @see MongoDB\ Collection::getFindOneAndDelete() for supported $options
755
+ * @see Collection::getFindOneAndDelete() for supported $options
756
756
*
757
757
* @param array $filter The $filter criteria to search for
758
758
* @param array $options Additional options
@@ -767,7 +767,7 @@ public function findOneAndDelete(array $filter, array $options = array())
767
767
"query " => $ filter ,
768
768
) + $ options ;
769
769
770
- $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->getResponseDocument ();
770
+ $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray ();
771
771
if ($ doc ["ok " ]) {
772
772
return $ doc ["value " ];
773
773
}
@@ -778,7 +778,7 @@ public function findOneAndDelete(array $filter, array $options = array())
778
778
/**
779
779
* Retrieves all findOneDelete options with their default values.
780
780
*
781
- * @return array of MongoDB\ Collection::findOneAndDelete() options
781
+ * @return array of Collection::findOneAndDelete() options
782
782
*/
783
783
public function getFindOneAndDeleteOptions ()
784
784
{
@@ -811,10 +811,10 @@ public function getFindOneAndDeleteOptions()
811
811
* Finds a single document and replaces it, returning either the original or the replaced document
812
812
* By default, returns the original document.
813
813
* To return the new document set:
814
- * $options = array("returnDocument" => MongoDB\ Collection::FIND_ONE_AND_RETURN_AFTER);
814
+ * $options = array("returnDocument" => Collection::FIND_ONE_AND_RETURN_AFTER);
815
815
*
816
816
* @see http://docs.mongodb.org/manual/reference/command/findAndModify/
817
- * @see MongoDB\ Collection::getFindOneAndReplace() for supported $options
817
+ * @see Collection::getFindOneAndReplace() for supported $options
818
818
*
819
819
* @param array $filter The $filter criteria to search for
820
820
* @param array $replacement The document to replace with
@@ -835,7 +835,7 @@ public function findOneAndReplace(array $filter, array $replacement, array $opti
835
835
"query " => $ filter ,
836
836
) + $ options ;
837
837
838
- $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->getResponseDocument ();
838
+ $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray ();
839
839
if ($ doc ["ok " ]) {
840
840
return $ doc ["value " ];
841
841
}
@@ -846,7 +846,7 @@ public function findOneAndReplace(array $filter, array $replacement, array $opti
846
846
/**
847
847
* Retrieves all findOneAndReplace options with their default values.
848
848
*
849
- * @return array of MongoDB\ Collection::findOneAndReplace() options
849
+ * @return array of Collection::findOneAndReplace() options
850
850
*/
851
851
public function getFindOneAndReplaceOptions ()
852
852
{
@@ -895,11 +895,11 @@ public function getFindOneAndReplaceOptions()
895
895
* Finds a single document and updates it, returning either the original or the updated document
896
896
* By default, returns the original document.
897
897
* To return the new document set:
898
- * $options = array("returnDocument" => MongoDB\ Collection::FIND_ONE_AND_RETURN_AFTER);
898
+ * $options = array("returnDocument" => Collection::FIND_ONE_AND_RETURN_AFTER);
899
899
*
900
900
*
901
901
* @see http://docs.mongodb.org/manual/reference/command/findAndModify/
902
- * @see MongoDB\ Collection::getFindOneAndUpdate() for supported $options
902
+ * @see Collection::getFindOneAndUpdate() for supported $options
903
903
*
904
904
* @param array $filter The $filter criteria to search for
905
905
* @param array $update An array of update operators to apply to the document
@@ -920,7 +920,7 @@ public function findOneAndUpdate(array $filter, array $update, array $options =
920
920
"query " => $ filter ,
921
921
) + $ options ;
922
922
923
- $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->getResponseDocument ();
923
+ $ doc = $ this ->_runCommand ($ this ->dbname , $ cmd )->toArray ();
924
924
if ($ doc ["ok " ]) {
925
925
return $ doc ["value " ];
926
926
}
@@ -931,7 +931,7 @@ public function findOneAndUpdate(array $filter, array $update, array $options =
931
931
/**
932
932
* Retrieves all findOneAndUpdate options with their default values.
933
933
*
934
- * @return array of MongoDB\ Collection::findOneAndUpdate() options
934
+ * @return array of Collection::findOneAndUpdate() options
935
935
*/
936
936
public function getFindOneAndUpdateOptions ()
937
937
{
0 commit comments