Skip to content

Version fields are not indexed when indexSortableFields is true #4974

Closed

Description

@lohmander

Link to reproduction

No response

Describe the Bug

I'm not sure if this is intended behavior, but if versioning is enabled and indexSortableFields is set to true, the fields on the version fields are nevertheless missing indexes. When using a database that requires these indices, like CosmosDB in our case, look ups for relationships fail.

ezgif-4-e5cd20f0f4

I found that updating the monogdb-adapter and passing the indexSortableFields to the versionSchema appears to solve the problem:

+++ b/dist/init.js
@@ -30,6 +30,7 @@ const init = async function init() {
             const versionSchema = (0, _buildSchema.default)(this.payload.config, versionCollectionFields, {
                 disableUnique: true,
                 draftsEnabled: true,
+                indexSortableFields: this.payload.config.indexSortableFields,
                 options: {
                     minimize: false,
                     timestamps: false

However, I'm not sure this is an appropriate fix, or if it'll have other unwanted consequences.

To Reproduce

We've only run this against cosmos db.

  1. Create two collections with versioning (and drafts?) enabled
  2. Create a relationship field from one to the other
  3. Open the admin, and create an entity in the target collection
  4. Create another entity in collection referencing the target collection
  5. Attempt to select an item from the target collection, it should break

Payload Version

2.8.2

Adapters and Plugins

db-mongodb

Activity

  1. added
    status: needs-triage
    on Feb 2, 2024
  2. added
    db: mongodb
    on Feb 6, 2024
  3. github-actions commented on Sep 7, 2024

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  4. locked as resolved and limited conversation to collaborators on Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

db: mongodbstatus: needs-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions