fix(db-mongodb): find id field from flattened fields#15110
Merged
JarrodMFlesch merged 6 commits intomainfrom Jan 8, 2026
Merged
fix(db-mongodb): find id field from flattened fields#15110JarrodMFlesch merged 6 commits intomainfrom
JarrodMFlesch merged 6 commits intomainfrom
Conversation
Contributor
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
paulpopus
previously approved these changes
Jan 8, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes custom ID fields nested within tabs or groups to work correctly with MongoDB adapter. Previously, MongoDB's schema builder only searched top-level fields, causing nested custom IDs to be ignored and falling back to auto-generated ObjectIDs.
- Pass flattenedFields to MongoDB schema builder to find custom ID fields regardless of nesting level
- Track field depth in afterRead hooks to prevent hidden top-level custom ID fields from being removed
- Add comprehensive test coverage for nested custom ID functionality
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/fields/slugs.ts | Adds slug constant for new CustomIDNested test collection |
| test/fields/payload-types.ts | Adds TypeScript type definitions for CustomIDNested collection |
| test/fields/int.spec.ts | Adds comprehensive test suite for nested custom ID functionality |
| test/fields/collections/CustomIDNested/index.ts | Creates new test collection with numeric ID field nested in unnamed tab |
| test/fields/baseConfig.ts | Registers CustomIDNested collection in test configuration |
| packages/payload/src/fields/hooks/afterRead/traverseFields.ts | Adds fieldDepth parameter to track nesting level during field traversal |
| packages/payload/src/fields/hooks/afterRead/promise.ts | Implements depth tracking logic and prevents removal of top-level hidden ID fields |
| packages/payload/src/fields/hooks/afterRead/index.ts | Initializes fieldDepth at entry point |
| packages/db-mongodb/src/models/buildSchema.ts | Updates schema builder to search flattenedFields for custom ID field |
| packages/db-mongodb/src/models/buildCollectionSchema.ts | Passes flattenedFields to buildSchema function |
| CLAUDE.md | Documents test cleanup best practices and pattern examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
paulpopus
approved these changes
Jan 8, 2026
Contributor
|
🚀 This is included in version v3.71.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14927
Summary
Fixes custom ID fields that are nested within tabs/groups to work correctly with MongoDB adapter.
Problem
When a custom id field was nested inside tabs or other unnamed grouping fields, MongoDB's schema builder couldn't find it because it only searched top-level fields. This caused the custom ID to be ignored and MongoDB would fall back to auto-generating ObjectIDs.
Solution
Testing
Added new CustomIDNested collection and comprehensive tests covering: