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.

Querying nested-docs

default discord avatar
zoul08132 years ago
2

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



Given the following paths:


/parent-page
/parent-page/child-page
/parent-page/child-page/grandchild-page


/api/pages?where[breadcrumbs.url][equals]=/parent-page/child-page



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

url

into a

path

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

where[path][equals]=/parent-page/child-page

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

  • discord user avatar
    jacobsfletch
    2 years ago

    That url probably fails because the forward slashes in your

    where

    query are not encoded, which would look like this:

    /api/pages?where[breadcrumbs.url][equals]=%2Fparent-page%2Fchild-page

    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

    slug

    then find the document whose

    last

    breadcrumb matches your url

  • default discord avatar
    zoul08132 years 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 ...



    ?where[breadcrumbs.url][equals]=/new-page/child-page/grandchild-page&where[slug][equals]=grandchild-page


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

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.