Dynamic Fields - Point to Point Distance

default discord avatar
wmcmorrow2
2 months ago
1

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
    jarrod_not_jared
    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!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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