11
11
use MongoDB \Exception \InvalidArgumentException ;
12
12
use MongoDB \Exception \UnexpectedValueException ;
13
13
use MongoDB \Exception \UnsupportedException ;
14
+ use MongoDB \Model \TypeMapArrayIterator ;
14
15
use ArrayIterator ;
15
16
use stdClass ;
16
17
use Traversable ;
@@ -72,9 +73,6 @@ class Aggregate implements Executable
72
73
* * typeMap (array): Type map for BSON deserialization. This will be
73
74
* applied to the returned Cursor (it is not sent to the server).
74
75
*
75
- * This is not supported for inline aggregation results (i.e. useCursor
76
- * option is false or the server version is < 2.6).
77
- *
78
76
* * useCursor (boolean): Indicates whether the command will request that
79
77
* the server provide results using a cursor. The default is true.
80
78
*
@@ -206,9 +204,6 @@ public function execute(Server $server)
206
204
$ cursor = $ server ->executeCommand ($ this ->databaseName , $ command , $ readPreference );
207
205
208
206
if ($ isCursorSupported && $ this ->options ['useCursor ' ]) {
209
- /* The type map can only be applied to command cursors until
210
- * https://jira.mongodb.org/browse/PHPC-314 is implemented.
211
- */
212
207
if (isset ($ this ->options ['typeMap ' ])) {
213
208
$ cursor ->setTypeMap ($ this ->options ['typeMap ' ]);
214
209
}
@@ -222,6 +217,10 @@ public function execute(Server $server)
222
217
throw new UnexpectedValueException ('aggregate command did not return a "result" array ' );
223
218
}
224
219
220
+ if (isset ($ this ->options ['typeMap ' ])) {
221
+ return new TypeMapArrayIterator ($ result ->result , $ this ->options ['typeMap ' ]);
222
+ }
223
+
225
224
return new ArrayIterator ($ result ->result );
226
225
}
227
226
0 commit comments