@payloadcms/plugin-relationship-object-ids
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

Payload Relationship ObjectID Plugin

This plugin automatically enables all Payload relationship and upload field types to be stored as ObjectIDs in MongoDB.

Minimum required version of Payload: 1.9.5

What it does

It injects a beforeChange field hook into each relationship and upload field, which converts string-based IDs to ObjectIDs immediately prior to storage.

Usage

Simply import and install the plugin to make it work:

import { relationshipsAsObjectID } from '@payloadcms/plugin-relationship-object-ids'
import { buildConfig } from 'payload/config'

export default buildConfig({
  // your config here
  plugins: [
    // Call the plugin within your `plugins` array
    relationshipsAsObjectID()
  ]
})

Migration

Note - this plugin will only store newly created or resaved documents' relations as ObjectIDs. It will not modify any of your existing data. If you'd like to convert existing data into an ObjectID format, you should write a migration script to loop over all documents in your database and then simply resave each one.

Support

If you need help with this plugin, join our Discord and we'd be happy to give you a hand.

Readme

Keywords

none

Package Sidebar

Install

npm i @payloadcms/plugin-relationship-object-ids

Weekly Downloads

34

Version

0.0.4

License

MIT

Unpacked Size

18.2 kB

Total Files

16

Last publish

Collaborators

  • jesschow
  • jarrodmflesch
  • danribbens
  • elliotpayload
  • jacobsfletch
  • payloadjs