Skip to content

fix(db-mongodb): handle admin.condition in sparse unique indexes#1

Merged
rachit367 merged 1 commit into
mainfrom
fix-conditional-sparse-index
May 18, 2026
Merged

fix(db-mongodb): handle admin.condition in sparse unique indexes#1
rachit367 merged 1 commit into
mainfrom
fix-conditional-sparse-index

Conversation

@rachit367
Copy link
Copy Markdown
Owner

What?

Fixes an issue where conditionally required unique fields created non-sparse MongoDB indexes.

Why?

Fields using admin.condition can be optional at runtime, but the current logic only checks the static required property.

This causes duplicate key errors when multiple documents contain null values.

How?

Updated sparse index logic in buildSchema.ts to account for admin.condition.

Fixes payloadcms#16298

@rachit367 rachit367 force-pushed the fix-conditional-sparse-index branch from 8c944c8 to 09c9f40 Compare May 17, 2026 08:08
@rachit367 rachit367 merged commit 1e3e7d8 into main May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[db:mongodb] Non-sparse unique index created for conditionally required fields

1 participant