Querying nested-docs

default discord avatar
Davidlast year

What is the recommended way of querying nested-docs when you know the path?

Given the following paths:



This query returns both the child-page document, and the grandchild-page document ...

I'm having trouble figuring out how to retrieve only the page that matches this path exactly. I am temporarily using a hidden auto-generated field, that takes the last breadcrumb and stores it's


into a


field at the document root ... so I can query


but this seems awkward, and I'm assuming there's a proper way to query nested-docs?

  • discord user avatar
    last year

    That url probably fails because the forward slashes in your


    query are not encoded, which would look like this:


    But this may match on multiple docs instead of just one, because the breadcrumb may appear across more than one document, especially within the same tree.

    You may want to query by


    then find the document whose


    breadcrumb matches your url

  • default discord avatar
    Davidlast year

    thanks - I think that helped. I just added the slug to the query and that seems to have resolved it ...

    I now have something like this ...


    The URL does get encoded by the browser before sending, I'm just showing the decoded version for readability.

Star on GitHub


Chat on Discord



Can't find what you're looking for?

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