@@ -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
*
@@ -255,6 +262,11 @@ public function getFresh($columns = [])
255
262
'typeMap ' => ['root ' => 'array ' , 'document ' => 'array ' ],
256
263
];
257
264
265
+ // Add custom query options
266
+ if (count ($ this ->options )) {
267
+ $ options = array_merge ($ options , $ this ->options );
268
+ }
269
+
258
270
// Execute aggregation
259
271
$ results = iterator_to_array ($ this ->collection ->aggregate ($ pipeline , $ options ));
260
272
@@ -313,6 +325,11 @@ public function getFresh($columns = [])
313
325
// Fix for legacy support, converts the results to arrays instead of objects.
314
326
$ options ['typeMap ' ] = ['root ' => 'array ' , 'document ' => 'array ' ];
315
327
328
+ // Add custom query options
329
+ if (count ($ this ->options )) {
330
+ $ options = array_merge ($ options , $ this ->options );
331
+ }
332
+
316
333
// Execute query and get MongoCursor
317
334
$ cursor = $ this ->collection ->find ($ wheres , $ options );
318
335
@@ -1020,6 +1037,19 @@ protected function compileWhereRaw($where)
1020
1037
return $ where ['sql ' ];
1021
1038
}
1022
1039
1040
+ /**
1041
+ * Set custom options for the query.
1042
+ *
1043
+ * @param array $options
1044
+ * @return $this
1045
+ */
1046
+ public function options (array $ options )
1047
+ {
1048
+ $ this ->options = $ options ;
1049
+
1050
+ return $ this ;
1051
+ }
1052
+
1023
1053
/**
1024
1054
* Handle dynamic method calls into the method.
1025
1055
*
0 commit comments