Skip to content

Commit df344de

Browse files
committed
Support query timeout as decimal number of seconds
1 parent bbf14b0 commit df344de

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Query/Builder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class Builder extends BaseBuilder
103103
/**
104104
* The maximum amount of seconds to allow the query to run.
105105
*
106-
* @var int
106+
* @var int|float
107107
*/
108108
public $timeout;
109109

@@ -214,7 +214,7 @@ public function project($columns)
214214
/**
215215
* The maximum amount of seconds to allow the query to run.
216216
*
217-
* @param int $seconds
217+
* @param int|float $seconds
218218
*
219219
* @return $this
220220
*/
@@ -457,7 +457,7 @@ public function toMql(): array
457457

458458
// Apply order, offset, limit and projection
459459
if ($this->timeout) {
460-
$options['maxTimeMS'] = $this->timeout * 1000;
460+
$options['maxTimeMS'] = (int) ($this->timeout * 1000);
461461
}
462462

463463
if ($this->orders) {

tests/Query/BuilderTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,11 @@ function (Builder $elemMatchQuery): void {
14371437
['find' => [[], ['hint' => ['foo' => 1]]]],
14381438
fn (Builder $builder) => $builder->hint(['foo' => 1]),
14391439
];
1440+
1441+
yield 'timeout' => [
1442+
['find' => [[], ['maxTimeMS' => 2345]]],
1443+
fn (Builder $builder) => $builder->timeout(2.3456),
1444+
];
14401445
}
14411446

14421447
#[DataProvider('provideExceptions')]

0 commit comments

Comments
 (0)