Skip to content

Commit b9d6867

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

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

Diff for: src/Query/Builder.php

+3-10
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) {
@@ -1555,13 +1555,6 @@ public function readPreference(string $mode, ?array $tagSets = null, ?array $opt
15551555
return $this;
15561556
}
15571557

1558-
public function typeMap(array $typeMap): static
1559-
{
1560-
$this->options['typeMap'] = $typeMap;
1561-
1562-
return $this;
1563-
}
1564-
15651558
/**
15661559
* Performs a full-text search of the field or fields in an Atlas collection.
15671560
* NOTE: $search is only available for MongoDB Atlas clusters, and is not available for self-managed deployments.

Diff for: tests/Query/BuilderTest.php

+5
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)