From 511a476f3e024cd8ed31dc5385b36e28725d0f59 Mon Sep 17 00:00:00 2001 From: Ali Jafari Date: Fri, 6 Sep 2024 13:43:57 +0200 Subject: [PATCH] Gracefully handle search index exceptions on non MongoDB Atlas (#2673) * Gracefully handle search index exceptions on non MongoDB Atlas * Fix php Coding Standards pipeline --- lib/Doctrine/ODM/MongoDB/SchemaManager.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Doctrine/ODM/MongoDB/SchemaManager.php b/lib/Doctrine/ODM/MongoDB/SchemaManager.php index c7d7f9b3b..b142f1902 100644 --- a/lib/Doctrine/ODM/MongoDB/SchemaManager.php +++ b/lib/Doctrine/ODM/MongoDB/SchemaManager.php @@ -1062,6 +1062,11 @@ private function isSearchIndexCommandException(CommandException $e): bool return true; } + // MongoDB 6.0.7+ and 7.0+: "$listSearchIndexes stage is only allowed on MongoDB Atlas" + if ($e->getMessage() === '$listSearchIndexes stage is only allowed on MongoDB Atlas') { + return true; + } + // Older server versions don't support $listSearchIndexes // We don't check for an error code here as the code is not documented and we can't rely on it return str_contains($e->getMessage(), 'Unrecognized pipeline stage name: \'$listSearchIndexes\'');