Commit 0f2520f2 authored by Ryan Hayle's avatar Ryan Hayle Committed by Jens Segers

Allow setting custom options on a query [Fixes #541] (#959)

parent ca4914cc
......@@ -41,6 +41,13 @@ class Builder extends BaseBuilder
*/
public $hint;
/**
* Custom options to add to the query.
*
* @var array
*/
public $options = [];
/**
* Indicate if we are executing a pagination query.
*
......@@ -263,6 +270,11 @@ class Builder extends BaseBuilder
'typeMap' => ['root' => 'array', 'document' => 'array'],
];
// Add custom query options
if (count($this->options)) {
$options = array_merge($options, $this->options);
}
// Execute aggregation
$results = iterator_to_array($this->collection->aggregate($pipeline, $options));
......@@ -321,6 +333,11 @@ class Builder extends BaseBuilder
// Fix for legacy support, converts the results to arrays instead of objects.
$options['typeMap'] = ['root' => 'array', 'document' => 'array'];
// Add custom query options
if (count($this->options)) {
$options = array_merge($options, $this->options);
}
// Execute query and get MongoCursor
$cursor = $this->collection->find($wheres, $options);
......@@ -1019,6 +1036,19 @@ class Builder extends BaseBuilder
return $where['sql'];
}
/**
* Set custom options for the query.
*
* @param array $options
* @return $this
*/
public function options(array $options)
{
$this->options = $options;
return $this;
}
/**
* Handle dynamic method calls into the method.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment