breadcrumbs query using nested docs

default discord avatar
last month

im using the nested docs plugin to create pages, now i want to get a page based on the url it has, which basically means the last item in the breadcrumbs array that is created. the ai-help suggested this query:


which looks like this for me:


this simply doesnt work, however removing [$last] does filter on the breadcrumbs.url, but it does so on all the fields.

what is the correct query to use here?

  • default discord avatar
    last month

    I use the following query to retrieve documents by path


    Or, put another way ...

    const query = {
      'breadcrumbs.url': {
        equals: `/${pathArray.join('/')}`,
      'slug': {
        equals: pathArray.slice(-1)[0],

    the end result here is that you should not have multiple documents that match both the breadcrumb url (at any level of the array), and the slug ...

    If your URL's look like


    then you'll have problems here ... as a request for


    will match all children as well, the requesting code would then need to go through the array of docs returned and find the appropriate match ... but hopefully, your URL structure is sane and doesn't contain repetitions like this.

  • default discord avatar
    last month

    this make perfect sense, ill try this, thanks david

    this solved it, where[breadcrumbs.url][equals]=/path/to/slug&where[slug][equals]=slug

    you saved my day

  • discord user avatar
    Payload Team
    last month

    Hey @olarssony glad this was sorted out!

    Thanks @zoul0813 !

  • default discord avatar
    last month

    This is related to a question I just posted here
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

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