@@ -41,6 +41,13 @@ class Builder extends BaseBuilder
4141 */
4242 public $ hint ;
4343
44+ /**
45+ * Custom options to add to the query.
46+ *
47+ * @var array
48+ */
49+ public $ options = [];
50+
4451 /**
4552 * Indicate if we are executing a pagination query.
4653 *
@@ -263,6 +270,11 @@ public function getFresh($columns = [])
263270 'typeMap ' => ['root ' => 'array ' , 'document ' => 'array ' ],
264271 ];
265272
273+ // Add custom query options
274+ if (count ($ this ->options )) {
275+ $ options = array_merge ($ options , $ this ->options );
276+ }
277+
266278 // Execute aggregation
267279 $ results = iterator_to_array ($ this ->collection ->aggregate ($ pipeline , $ options ));
268280
@@ -321,6 +333,11 @@ public function getFresh($columns = [])
321333 // Fix for legacy support, converts the results to arrays instead of objects.
322334 $ options ['typeMap ' ] = ['root ' => 'array ' , 'document ' => 'array ' ];
323335
336+ // Add custom query options
337+ if (count ($ this ->options )) {
338+ $ options = array_merge ($ options , $ this ->options );
339+ }
340+
324341 // Execute query and get MongoCursor
325342 $ cursor = $ this ->collection ->find ($ wheres , $ options );
326343
@@ -1019,6 +1036,19 @@ protected function compileWhereRaw($where)
10191036 return $ where ['sql ' ];
10201037 }
10211038
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+
10221052 /**
10231053 * Handle dynamic method calls into the method.
10241054 *
0 commit comments