Skip to content

Commit 310e126

Browse files
committed
Fix detection for mongodb community 5
1 parent 6c73f9d commit 310e126

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Exception/SearchNotSupportedException.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,31 @@ public static function create(ServerException $e): self
2020
}
2121

2222
/** @internal */
23-
public static function isSearchNotSupportedError(Throwable $e): bool
23+
public static function isSearchNotSupportedError(Throwable $exception): bool
2424
{
25-
if (! $e instanceof ServerException) {
25+
if (! $exception instanceof ServerException) {
2626
return false;
2727
}
2828

29-
return match ($e->getCode()) {
29+
return match ($exception->getCode()) {
3030
// MongoDB 8: Using Atlas Search Database Commands and the $listSearchIndexes aggregation stage requires additional configuration.
3131
31082 => true,
3232
// MongoDB 7: $listSearchIndexes stage is only allowed on MongoDB Atlas
3333
6047401 => true,
3434
// MongoDB 7-ent: Search index commands are only supported with Atlas.
3535
115 => true,
3636
// MongoDB 4 to 6, 7-community
37-
59 => 'no such command: \'createSearchIndexes\'' === $e->getMessage(),
37+
59 => match ($exception->getMessage()) {
38+
'no such command: \'createSearchIndexes\'' => true,
39+
'no such command: \'updateSearchIndex\'' => true,
40+
'no such command: \'dropSearchIndex\'' => true,
41+
default => false,
42+
},
3843
// MongoDB 4 to 6
39-
40324 => 'Unrecognized pipeline stage name: \'$listSearchIndexes\'' === $e->getMessage(),
44+
40324 => match ($exception->getMessage()) {
45+
'Unrecognized pipeline stage name: \'$listSearchIndexes\'' => true,
46+
default => false,
47+
},
4048
// Not an Atlas Search error
4149
default => false,
4250
};

tests/Exception/SearchNotSupportedExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testListSearchIndexesNotSupportedException(): void
2424
}
2525

2626
#[DoesNotPerformAssertions]
27-
public function testCreateSearchIndexNotSupportedException(): void
27+
public function testSearchIndexManagementNotSupportedException(): void
2828
{
2929
$collection = $this->createCollection($this->getDatabaseName(), 'SearchNotSupportedException');
3030

0 commit comments

Comments
 (0)