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

Querying nested-docs

3 weeks ago

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?

  • jacobsfletch
    Payload Team
    3 weeks ago

    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

  • David
    3 weeks ago

    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.

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