RavenDb - Recursive Queries / Indexes, for a Hierarchical Document

I know this may be a little silly question, maybe wrong, but I will ask any way.

Suppose I have a set of Hierarchical documents. The only information they contain about their place in the hierarchy is their parent identifier. If its value is null, we have reached the top.

Getting parents and children is the easy part.

I want to make a request for all descendants and ancestors. I think I have to figure this out. 1) Get ancestors in a document - is this any way to make a recursive query? Get the parent parent until the parent is zero.

2) Do they have any way to make an index / projection where we can match the Ancestor ID to the document. Then request an ancestor id or document id? Because, if I could get this index, it would be easy to say to get all documents by ancestor identifier for a document identifier equal to documentid I ​​want children to be.

Let's say I have this structure.

Document 1
Document 1.1
Document 1.1.1
Document 1.1.2
Document 1.2
Document 1.2.1

I need an index similar to this

DocumentID
1.1
1.1.1
1.1.1
1.1.2
1.1.2
1.2
1.2.1
1.2.1

AncestorID 1
1
1.1
1
1.1
1
1.2

+4
source share
1 answer

This has been discussed in detail on the RavenDB mailing list: https://groups.google.com/d/topic/ravendb/ptBYL9A5PA8/discussion

The solution I selected included a complete pedigree in each document.

+3
source

Source: https://habr.com/ru/post/1332502/


All Articles