Query by URI/nested slug

We have a model called Page which can be used to created nested pages:

- one
-- two
--- three

On the frontend, this results in a URI like /one/two/three. Is there a way to query for a model using the full URI/nested slug? If not, how would we fetch three from the CMS based only on the URI? Assuming the depth could be anywhere between 1-6 and there could be multiple pages with a matching slug at different depths.

E.g. /one/two/three and /example/three

Hi David! No, there’s no specific query you can use for this, I guess you need to fetch all the slugs of the tree and traverse them yourself :confused:

Hey Stefano, thanks for getting back to me so quickly.

Is this something that is on the roadmap? It seems like something that would be super useful for any site using datocms as a source for nested content pages.

Do you mean by fetching all the pages, constructing the URIs and doing a lookup? Will there be any performance issues if there are a lot of pages?

Cheers

David

Regarding the performance, how many records do you plan to have? You can fetch 500 records per call.

Then you would need to rebuild the tree on your end and traverse it to find the content that you need. I’m not sure, but I don’t think it will be very time consuming. On the plus side, once you have the tree on your end the traversals would be much faster than calling an API though.

Hi Mat. Not sure yet, although I think it is unlikely we’ll hit the 500 limit any time soon.

Do you have an example of building the tree structure in javascript using the parent/child relationships?

Yes, have a look here: https://www.datocms.com/docs/content-management-api/resources/item/create#tree-like-structure

Let me know if you have any doubts