I have noticed that the object ID is stored as a string in MongoDB. Is there a way to store it as ObjectID? It would be easier if the type is ObjectID for easier lookups.
I am referring to the tutorial here:
Hey @rarcif — we store object IDs as strings intentionally, and there is no real easy way to store them as full ObjectIDs. This is for a few reasons, but we could certainly evaluate a way to be able to "opt in" to ObjectIDs instead of string representations in a new feature
there are a few places in the code that would need to be adjusted, but technically, this could be doable with a PR
right now, it's not possible though
@jmikrut Is there a way to handle this with custom code? Example, by using hooks?
collection hook and a
to transform any relationship field string IDs to ObjectIDs before storage, and the
to convert them back to strings
Hey @gokulsck — I just looked into this and built a plugin to do exactly what you thought - - just add a field hook to each relationship / upload field to convert to ObjectIDs before storage:
nice and simple 👍 good question! this is a nice thing to have!
Thanks will check it...
@jmikrut This solution is working. Thanks for the quick fix. Still just wanted to know if this is under testing or not? Because I did not see the details updated in the payload documentation of the relationship. Could you confirm this is an official release or not?
This is an official release, but it is a plugin, so it won't be listed in the Payload docs directly as it's not a part of "core" specifically. But it is officially supported and will continue to be
in the future, we will be listing all of our official plugins in the Payload docs, and this one will be listed as well
Hey @jmikrut I have noticed an issue, the filter is not working as expected for relationship field. Could you confirm that, the plugin you implemented works or not for relationship fields filtering?
let me check on this immediately
@gokulsck It appears relationship filtering is not working as expected. Looking into a fix now.
Issue logged here. Expect this to be taken care of in a day or two.
hey @gokulsck - just a heads-up, we fixed this!
you shouldn't need to update your plugin, instead, you should just update your Payload version to the newest
i also added a test suite to the plugin to make sure that it's nice and covered