Field indexes not being created

default discord avatar
devperson
3 months ago
3

Bit of a weird one -- been debugging some performance issues with Payload and have noticed some of the indexes we defined on a field haven't been working



This doesn't seem to be happening consistently across our application, for example this field did not have an index:



{
  name: 'externalId',
  label: 'External ID',
  type: 'text',
  access: {
    read: adminOnly,
    update: () => false
  },
  index: true,
  unique: true
},


Other similar fields have had an index though, for example this slug index:



{
  name: 'slug',
  type: 'text',
  label: 'Slug',
  index: true,
  unique: true,
  admin: {
    description:
      'The unique identifier for this page. This will be used in the URL.',
    position: 'sidebar'
  },


Anyone got any insights to this?



Running


const members = payload.collections['members'].Model

await members.syncIndexes()

creates the index

  • default discord avatar
    nikich
    3 months ago

    Hey, @devperson! Have you applied

    index: true

    after collection items was created? If yes, this might be the issue, AFAIK.

  • default discord avatar
    devperson
    3 months ago

    Ah yeah, good to know

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.