Near operator isn't ordering items

default discord avatar
wmcmorrow212 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 👍

    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

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