Modelling tree structure?

22 views
Skip to first unread message

Jiri Jakes

unread,
Jan 14, 2012, 3:34:04 AM1/14/12
to mongo-scala-driver
Hello.

I'm playing with mongo-scala-driver and wondering whether it is
possible to model a tree. For example comments forming a hierarchy.

article : {
title : "...",
comments : [
{ text : "...", replies : [] },
{ text : "...", replies : [
{ "text : "...", replies : [] },
{ "text : "...", replies : [] }
]
]
}

where:


class Article(val title: String, val comments: List[Comment])
class Comment(val text: String, val replies: List[Comment])


With a help of manga-scala-driver's test in git and wiki I was able to
model a comment list without replies. But I don't know how to add the
replies to the comment. If I naively add


object replies extends ArrayEmbeddedField[Comment]("replies",
_.replies, None) with CommentIn[Comment]


to CommentIn trait, I intuitively feel that it is not correct (and
also does not compile).

Is there a way how to model tree structures with mongo-scala-driver?

Thank you.

Alexander Azarov

unread,
Jan 20, 2012, 4:01:56 AM1/20/12
to mongod...@googlegroups.com
Hello,

Sorry for the late reply, it seems that Google Groups notification was lost somewhere in Spam mailbox, so I didn't know there is a message waiting for moderation

Mongo-scala-driver requires a lot of boilerplate to express nested structures indeed. This is one of the reasons I've created the next generation library, "Subset". Please see the announcement in the group.

There is a similar example in Subset's documentation, please see here http://osinka.github.com/subset/Sub-document.html I expect you should have no problem creating extra level of nesting or more than one. I'd be grateful if you share your experience

Regards,
Alexander

Jiří Jakeš

unread,
Jan 20, 2012, 4:06:44 AM1/20/12
to mongod...@googlegroups.com
Hello.

No problem, thank you anyway.

Yes, I just read the announcement and going to observe Subset a bit.
If I discover something interesting, I will share.

J.

Reply all
Reply to author
Forward
0 new messages