Skip to content

Commit e2fc22d

Browse files
authored
fix: expire index already exists not triggering on v7 (#98) (#99)
1 parent 0e5402b commit e2fc22d

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

src/Serilog.Sinks.MongoDB/Helpers/MongoDbHelpers.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ internal static void VerifyCollectionExists(
5858
{
5959
database.CreateCollection(collectionName, collectionCreationOptions);
6060
}
61-
catch (MongoCommandException e) when (e.ErrorMessage.Contains(
62-
"collection already exists",
63-
StringComparison.InvariantCultureIgnoreCase))
61+
catch (MongoCommandException e) when (e.CodeName == "NamespaceExists")
6462
{
6563
// handled
6664
}
@@ -89,8 +87,7 @@ internal static void VerifyExpireTTLSetup(
8987

9088
return;
9189
}
92-
catch (MongoCommandException ex) when (ex.ErrorMessage.Contains(
93-
"already exists with different options"))
90+
catch (MongoCommandException ex) when (ex.CodeName == "IndexOptionsConflict")
9491
{
9592
// handled -- just drop and recreate
9693
logCollection.Indexes.DropOne(ExpireTTLIndexName);

0 commit comments

Comments
 (0)