Near operator isn't ordering items

default discord avatar
wmcmorrow2
2 months ago

I'm using the near operator to query a list of locations based on their proximity from me. The items seem to be returned in random order instead of the nearest first as defined in the documentation.



const lng = myProfile.location[0]


const lat = myProfile.location[1]



const query = {


location: {


near: [


lng,


lat,


10000,


]


},


and: [


{


subcategories: {


equals: subcategory,


}


},


]


};


const stringifiedQuery = qs.stringify(


{


where: query,


},


{ addQueryPrefix: true },


);



I'm using Payload 1.9.1. Could this be a bug?



Ahh looks like it's a known issue



https://github.com/payloadcms/payload/issues/2848


Upgrading to the latest version fixed the issue 👍

    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.