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:
/api/collection?where[arrayField][$last][equals]=desiredValue
which looks like this for me:
/api/mainPages?where[breadcrumbs.url][$last][equals]=/projekt
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?
I use the following query to retrieve documents by path
where[breadcrumbs.url][equals]=/path/to/slug&where[slug][equals]=slug
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
/foo/foo/foo/foo
then you'll have problems here ... as a request for
/foo/foo
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.
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
Hey @olarssony glad this was sorted out!
Thanks @zoul0813 !
This is related to a question I just posted here
https://discord.com/channels/967097582721572934/1162319476969189456Star
Discord
online
Get help straight from the Payload team with an Enterprise License.