Pergunta

I know this might be a bit of a silly question, probably doing it wrong but I'll ask any way.

Lets say I have a set of Hierarchical Documents. The only information they contain about their place in the hierarchy is their parent id. If its null we have reached the top.

Getting parents and children are the easy part.

What I want to do is query for all the descendants and ancestors. I think I have to parts to this question. 1) To get the ancestors to a document is their any way to make a recursive query? Get the parent parent until parent is null.

2) Is their any way to make a index/projections where we can map the ancestor ids to a document. And then query the ancestor id or the document id? Because if I could get that index it would be easy to say get all documents by ancestor id for document id equal to the documentid i want to get the children from.

Lets 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 want a index looking somthing like 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

Foi útil?

Solução

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

The chosen solution, I believe, involved putting the full ancestry in each document.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top