Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

How to use near in a query?

default discord avatar
rafaelnep2 years ago
4

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
    paulpopus2 years 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 😅

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Hey

    @611775132754640896

    I have used em a bunch, just format em like this:



    coordinates: {
      near: [
        lng,
        lat,
        meters,
      ],
    }
  • default discord avatar
    rafaelnep2 years 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. 🤷‍♂️

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Awesome, happy to help. Have fun!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.