@@ -41,6 +41,13 @@ class Builder extends BaseBuilder
41
41
*/
42
42
public $ hint ;
43
43
44
+ /**
45
+ * Custom options to add to the query.
46
+ *
47
+ * @var array
48
+ */
49
+ public $ options = [];
50
+
44
51
/**
45
52
* Indicate if we are executing a pagination query.
46
53
*
@@ -263,6 +270,11 @@ public function getFresh($columns = [])
263
270
'typeMap ' => ['root ' => 'array ' , 'document ' => 'array ' ],
264
271
];
265
272
273
+ // Add custom query options
274
+ if (count ($ this ->options )) {
275
+ $ options = array_merge ($ options , $ this ->options );
276
+ }
277
+
266
278
// Execute aggregation
267
279
$ results = iterator_to_array ($ this ->collection ->aggregate ($ pipeline , $ options ));
268
280
@@ -321,6 +333,11 @@ public function getFresh($columns = [])
321
333
// Fix for legacy support, converts the results to arrays instead of objects.
322
334
$ options ['typeMap ' ] = ['root ' => 'array ' , 'document ' => 'array ' ];
323
335
336
+ // Add custom query options
337
+ if (count ($ this ->options )) {
338
+ $ options = array_merge ($ options , $ this ->options );
339
+ }
340
+
324
341
// Execute query and get MongoCursor
325
342
$ cursor = $ this ->collection ->find ($ wheres , $ options );
326
343
@@ -1019,6 +1036,19 @@ protected function compileWhereRaw($where)
1019
1036
return $ where ['sql ' ];
1020
1037
}
1021
1038
1039
+ /**
1040
+ * Set custom options for the query.
1041
+ *
1042
+ * @param array $options
1043
+ * @return $this
1044
+ */
1045
+ public function options (array $ options )
1046
+ {
1047
+ $ this ->options = $ options ;
1048
+
1049
+ return $ this ;
1050
+ }
1051
+
1022
1052
/**
1023
1053
* Handle dynamic method calls into the method.
1024
1054
*
0 commit comments