开发者

RavenDb - Recursive queries/indexes, for Hierarchical Document

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 pa开发者_JAVA技巧rent 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜