How to use near in a query?

default discord avatar
Rafael Nepomucenolast year
5

Does anyone have an example of how to use near in a query? I am getting the following error: "near must be first in: { $near: null }". It is requiring Float instead of coordinates and distance.

  • default discord avatar
    noheadphoneslast year

    Haven't used the points field yet but you might need to update the where query to use

    and

    so a bit like this


    where: {
      and: [
    {
    status: {equals: 'ON' }
    },
    {
    near: //...logic
    }
    ]
    }


    excuse the formatting 😅

  • default discord avatar
    Jarrodlast year

    Hey @Rafael Nepomuceno I have used em a bunch, just format em like this:



    coordinates: {
      near: [
        lng,
        lat,
        meters,
      ],
    }
  • default discord avatar
    Rafael Nepomucenolast year

    Wow! And that. I quickly tested it in graphql playground and it worked. Thank you very much. I was already connecting directly to mongo to solve this. 🤷‍♂️

  • default discord avatar
    Jarrodlast year

    Awesome, happy to help. Have fun!

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.