Skip to content

Custom id field with relationship BSONError #11820

@kolyasya

Description

@kolyasya

Describe the Bug

I have custom ids based on Meteor random id (because payload cms is used to manage Meteor's DB).

Everything works fine when I insert documents. They get properly generated ids via hook.

But once I establish relationship connection between 2 collections and try to add items of 2nd one to the 1st one I get:
BSONError: input must be a 24 character hex string, 12 byte Uint8Array, or an integer

Link to the code that reproduces this issue

Reproduction Steps

Just establish relationship connection between 2 collection with custom ids and try to insert a new document with related docs (which have custom Meteor ids):

{
      name: 'layers',
      type: 'array',
      fields: [
        {
          name: 'layer',
          type: 'relationship',
          relationTo: 'layer-materials',
          hasMany: false,
          required: true,
          label: 'Layer',
          admin: {
            sortOptions: 'type',
          },
        },
      ],
    },

Which area(s) are affected? (Select all that apply)

db-mongodb

Environment Info

Binaries:
  Node: 18.20.5
  npm: 10.8.2
  Yarn: N/A
  pnpm: 10.6.5
Relevant Packages:
  payload: 3.29.0
  next: 15.2.3
  @payloadcms/db-mongodb: 3.29.0
  @payloadcms/email-nodemailer: 3.29.0
  @payloadcms/graphql: 3.29.0
  @payloadcms/next/utilities: 3.29.0
  @payloadcms/payload-cloud: 3.29.0
  @payloadcms/richtext-lexical: 3.29.0
  @payloadcms/translations: 3.29.0
  @payloadcms/ui/shared: 3.29.0
  react: 19.1.0-canary-ff628334-20250205
  react-dom: 19.1.0-canary-ff628334-20250205
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions