Skip to content

Commit

Permalink
Merge 8a51887 into c25900b
Browse files Browse the repository at this point in the history
  • Loading branch information
divine committed Jan 31, 2020
2 parents c25900b + 8a51887 commit 5e2c922
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Jenssegers/Mongodb/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,12 @@ public function getFresh($columns = [])
if ($this->limit) {
$options['limit'] = $this->limit;
}
if ($this->hint) {
$options['hint'] = $this->hint;
}
if ($columns) {
$options['projection'] = $columns;
}
// if ($this->hint) $cursor->hint($this->hint);

// Fix for legacy support, converts the results to arrays instead of objects.
$options['typeMap'] = ['root' => 'array', 'document' => 'array'];
Expand Down
21 changes: 21 additions & 0 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,4 +737,25 @@ public function testValue()
$this->assertEquals('Herman', DB::collection('books')->value('author.first_name'));
$this->assertEquals('Melville', DB::collection('books')->value('author.last_name'));
}

public function testHintOptions()
{
DB::collection('items')->insert([
['name' => 'fork', 'tags' => ['sharp', 'pointy']],
['name' => 'spork', 'tags' => ['sharp', 'pointy', 'round', 'bowl']],
['name' => 'spoon', 'tags' => ['round', 'bowl']],
]);

$results = DB::collection('items')->hint(['$natural' => -1])->get();

$this->assertEquals('spoon', $results[0]['name']);
$this->assertEquals('spork', $results[1]['name']);
$this->assertEquals('fork', $results[2]['name']);

$results = DB::collection('items')->hint(['$natural' => 1])->get();

$this->assertEquals('spoon', $results[2]['name']);
$this->assertEquals('spork', $results[1]['name']);
$this->assertEquals('fork', $results[0]['name']);
}
}

0 comments on commit 5e2c922

Please sign in to comment.