How to use near in a query?

default discord avatar
Rafael Nepomuceno
6 months ago
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
    noheadphones
    6 months ago

    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
    Jarrod
    6 months ago

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



    coordinates: {
      near: [
        lng,
        lat,
        meters,
      ],
    }
  • default discord avatar
    Rafael Nepomuceno
    6 months ago

    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
    Jarrod
    6 months ago

    Awesome, happy to help. Have fun!

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.