Should relationship IDs be stored in Mongo as BSON ObjectID instead of string? #3019
Replies: 4 comments 4 replies
-
Hey @Moodycomputer! We've actually built a plugin to do exactly this, check it out: https://github.com/payloadcms/plugin-relationship-object-ids. The instructions in the README should be pretty explanatory but let me know if you have any questions. |
Beta Was this translation helpful? Give feedback.
-
@jacobsfletch This is exactly what I'm looking for, thank you! Out of curiosity, why is this method not the default? |
Beta Was this translation helpful? Give feedback.
-
@jacobsfletch Hi. help me please, how to fix bug plugin-relationship-object-ids payloadcms/plugin-relationship-object-ids#2 ? |
Beta Was this translation helpful? Give feedback.
-
Hi, it's hard to combine the following technologies on top of mongoDB because Payload does not support ObjectId relationships. The plugin is deprecated and I tried a pull request but there were issues : see payloadcms/plugin-relationship-object-ids#5
I'm using PayloadCMS over 30 collections with many relationships and this is the only thing that's in my way. All the rest is super smooth ;). |
Beta Was this translation helpful? Give feedback.
-
When saving a relationship field, should the ID of the target record be stored as a BSON ObjectID instead of a string? This seems to be the recommended best practice from MongoDB, and is the practice adopted by Mongoose for document population.
Today, this field configuration—
Saves to the database as—
Under this suggestion, that same configuration would save as
This would allow for sibling systems to access the Payload-connected database in a more standardized way, and allow for operations utilizing ObjectID helper functions within the database.
Beta Was this translation helpful? Give feedback.
All reactions