Skip to content

Commit 379ef87

Browse files
docs(db-mongodb): note on indexing localized fields & per-locale growth (#13469)
Closes #13464 Adds a note to the Indexes docs for localized fields: - Indexing a `localized: true` field creates one index per locale path (e.g. `slug.en`, `slug.da-dk`), which can grow index count on MongoDB. - Recommends defining explicit indexes via collection-level `indexes` for only the locale paths you actually query. - Includes a concrete example (index `slug.en` only). Docs-only change. --------- Co-authored-by: German Jablonski <43938777+GermanJablo@users.noreply.github.com>
1 parent 9f7d8c6 commit 379ef87

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

docs/database/indexes.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,22 @@ export const MyCollection: CollectionConfig = {
6363
],
6464
}
6565
```
66+
## Localized fields and MongoDB indexes
67+
68+
When you set `index: true` or `unique: true` on a localized field, MongoDB creates one index **per locale path** (e.g., `slug.en`, `slug.da-dk`, etc.). With many locales and indexed fields, this can quickly approach MongoDB's per-collection index limit.
69+
70+
If you know you'll query specifically by a locale, index only those locale paths using the collection-level `indexes` option instead of setting `index: true` on the localized field. This approach gives you more control and helps avoid unnecessary indexes.
71+
72+
```ts
73+
import type { CollectionConfig } from 'payload'
74+
75+
export const Pages: CollectionConfig = {
76+
fields: [{ name: 'slug', type: 'text', localized: true }],
77+
indexes: [
78+
// Index English slug only (rather than all locales)
79+
{ fields: ['slug.en'] },
80+
// You could also make it unique:
81+
// { fields: ['slug.en'], unique: true },
82+
],
83+
}
84+
```

0 commit comments

Comments
 (0)