Like what we’re doing? Star us on GitHub!

How to use near in a query?

Rafael Nepomuceno
last week
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.

Captura_de_tela_2023-03-08_023851.jpg
  • noheadphones
    last week

    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 😅

  • Jarrod
    Payload Team
    last week

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



    coordinates: {
      near: [
        lng,
        lat,
        meters,
      ],
    }
  • Rafael Nepomuceno
    last week

    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. 🤷‍♂️

  • Jarrod
    Payload Team
    last week

    Awesome, happy to help. Have fun!

Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More