Enhance unique index handling in Client class to prevent sparse index…#24
Enhance unique index handling in Client class to prevent sparse index…#24
Conversation
… usage when partialFilterExpression is present
WalkthroughClient::createIndexes now conditionally sets sparse => true for unique indexes only when partialFilterExpression is absent. If partialFilterExpression exists, sparse is not set. An explanatory comment was added. No other logic or public interfaces were changed. Changes
Sequence Diagram(s)sequenceDiagram
actor Caller
participant Client
participant MongoDB as MongoDB Server
Caller->>Client: createIndexes(indexes)
Client->>Client: For each index:\nif unique==true
alt unique and no partialFilterExpression
Client->>Client: add option sparse=true
else unique with partialFilterExpression
Client->>Client: do not set sparse
end
Client->>MongoDB: send createIndexes command
MongoDB-->>Client: acknowledgement/result
Client-->>Caller: return result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/Client.php (1)
405-408: Clarify comment and remove stale TODOThe comment still reads like a TODO even though behavior is implemented. Reword it to document the policy and rationale.
Apply this diff to update the comment:
- /** - * TODO: Unique Indexes are now sparse indexes, which results into incomplete indexes. - * However, if partialFilterExpression is present, we can't use sparse. - */ + /** + * Note: For unique indexes we default to 'sparse' to avoid uniqueness conflicts on missing fields. + * When 'partialFilterExpression' is present, do not use 'sparse' to avoid conflicts with partial indexes. + */
… usage when partialFilterExpression is present
Summary by CodeRabbit