Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Exception/SearchNotSupportedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace MongoDB\Exception;

use MongoDB\Driver\Exception\ServerException;
use Throwable;

use function in_array;

final class SearchNotSupportedException extends ServerException
{
public static function isSearchNotSupportedError(Throwable $e): bool
{
if (! $e instanceof ServerException) {
return false;
}

return in_array($e->getCode(), [
59, // MongoDB 4 to 6, 7-community: no such command: 'createSearchIndexes'
40324, // MongoDB 4 to 6: Unrecognized pipeline stage name: '$listSearchIndexes'
115, // MongoDB 7-ent: Search index commands are only supported with Atlas.
6047401, // MongoDB 7: $listSearchIndexes stage is only allowed on MongoDB Atlas
31082, // MongoDB 8: Using Atlas Search Database Commands and the $listSearchIndexes aggregation stage requires additional configuration.
], true);
}
}
12 changes: 11 additions & 1 deletion src/Operation/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
use MongoDB\Driver\Command;
use MongoDB\Driver\CursorInterface;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Driver\Exception\ServerException;
use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Driver\Session;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\SearchNotSupportedException;
use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException;
use MongoDB\Model\CodecCursor;
Expand Down Expand Up @@ -233,7 +235,15 @@ public function execute(Server $server): CursorInterface
$this->createCommandOptions(),
);

$cursor = $this->executeCommand($server, $command);
try {
$cursor = $this->executeCommand($server, $command);
} catch (ServerException $exception) {
if (SearchNotSupportedException::isSearchNotSupportedError($exception)) {
throw new SearchNotSupportedException('Search is not supported by the connected server', $exception->getCode(), $exception);
}

throw $exception;
}

if (isset($this->options['codec'])) {
return CodecCursor::fromCursor($cursor, $this->options['codec']);
Expand Down
Loading