Skip to content

Commit 12f51ba

Browse files
authored
fix(db-mongodb): remove duplicative indexing of timestamps (#11028)
### What? This PR removes a pair unnecessary calls to `schema.index` against the timestamp fields. The issue is when a user sets `indexSortableFields` as this is what will ultimately pass the predicate which then creates duplicate indexes. ### Why? These calls are redundant as `index` is [already passed](https://github.com/payloadcms/payload/blob/main/packages/db-mongodb/src/models/buildSchema.ts#L69) to the underlying fields base schema options in the process of formatting and will already be indexed. These warnings were surfaced after the bump to mongoose to version 8.9.5 as [in 8.9.3 mongoose began throwing these warnings to indicate duplicative indexes](https://github.com/Automattic/mongoose/releases/tag/8.9.3). ### How? By removing these calls and, as a result, silencing the warnings thrown by mongoose.
1 parent 4c8cafd commit 12f51ba

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

packages/db-mongodb/src/models/buildCollectionSchema.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ export const buildCollectionSchema = (
3434
schema.index(indexDefinition, { unique: true })
3535
}
3636

37-
if (payload.config.indexSortableFields && collection.timestamps !== false) {
38-
schema.index({ updatedAt: 1 })
39-
schema.index({ createdAt: 1 })
40-
}
41-
4237
schema
4338
.plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })
4439
.plugin(getBuildQueryPlugin({ collectionSlug: collection.slug }))

0 commit comments

Comments
 (0)