Dynamic Fields - Point to Point Distance

default discord avatar
2 months ago

I'm wondering whether it is possible to calculate the distance between two points in miles and return that as an attribute of requested documents. I think this would usually be done with aggregation in MongoDB. Is something like that possible? I may just do it in the front-end if not but curious if anyone has any thoughts on the best approach for this.

  • discord user avatar
    Payload Team
    2 months ago

    two points on the same doc? You could throw together another field that is stored on that doc and then use a beforeChange hook to calc the distance and store it on your new field

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


Connect with the Payload Community on Discord



Can't find what you're looking for?

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