From b2c89d4c21b77cfa3cb1b740bd0245c971040e7f Mon Sep 17 00:00:00 2001 From: shimon Date: Sun, 10 Aug 2025 15:40:53 +0300 Subject: [PATCH] Enhance unique index handling in Client class to prevent sparse index usage when partialFilterExpression is present --- src/Client.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 7a2273c..975d624 100644 --- a/src/Client.php +++ b/src/Client.php @@ -404,8 +404,11 @@ public function createIndexes(string $collection, array $indexes, array $options if (\array_key_exists('unique', $index) && $index['unique'] == true) { /** * TODO: Unique Indexes are now sparse indexes, which results into incomplete indexes. + * However, if partialFilterExpression is present, we can't use sparse. */ - $indexes[$key] = \array_merge($index, ['sparse' => true]); + if (!\array_key_exists('partialFilterExpression', $index)) { + $indexes[$key] = \array_merge($index, ['sparse' => true]); + } } }