Hard to start

8 views
Skip to first unread message

Freewind

unread,
Mar 20, 2011, 4:41:25 AM3/20/11
to mongo-scala-driver
After 1 day of tring, I have to say, it's hard to start with this
project. I mean, for the one-to-many, many-to-many, embedded array,
and so on, there is no good demo to learn.

I hope author can provide a complete demo ( which is complex enough ),
for example, a faq site:

User refs to many questions
Question refs to many answers
Question contains many tags
Question embeds many comments

I have read the wikis on github.com, some sources and tests of scala-
mongo-driver, but I still don't know, how to define:

A user refs many questions
Save a user with questions
Read a user with refs questions
....

Alexander Azarov

unread,
Mar 20, 2011, 4:45:50 AM3/20/11
to mongod...@googlegroups.com

20.03.2011 at 11:41, Freewind wrote

> After 1 day of tring, I have to say, it's hard to start with this
> project. I mean, for the one-to-many, many-to-many, embedded array,
> and so on, there is no good demo to learn.

The project's Specs cover most of these:

https://github.com/osinka/mongo-scala-driver/tree/master/src/test/scala/com/osinka/mongodb/shape

> I hope author can provide a complete demo ( which is complex enough ),
> for example, a faq site:

I have it: https://github.com/osinka/pocketchangeapp

Freewind

unread,
Mar 20, 2011, 8:33:08 AM3/20/11
to mongo-scala-driver
@Alexander, thank you very much, the `pocketchangeapp` helped me a
lot. But I met something not included in that project, now I have
something wrong I can't resolve. Please help me.

I have a `question` class, which contains some `comments`, the
comments are embedded array of question, so I defined:

class Question(val user: User) extends MongoObject with Oid {
var title: String = _
var comments: List[QComment] = Nil
}

object Question extends MongoObjectShape[Question] { shape =>
lazy val collection = db.getCollection("questions") of Question
lazy val user = Field.ref("user", User.collection, _.user)
lazy val title = Field.scalar("title", _.title, (q: Question, v:
String) => q.title = v)
// ******************* following seems not correct
object comments
extends ArrayEmbeddedField[QComment]("comments", _.comments,
Some((x: Question, v: Seq[QComment]) => { x.comments = v.toList }))
with QCommentIn[Question]
lazy override val * = user :: title :: comments :: Nil
override def factory(dbo: DBObject) = for (user(u) <- Some(dbo))
yield new Question(u)
// ******************
}

class QComment(val question: Question) extends MongoObject with Oid {
var content: String = _
}

trait QCommentIn[T] extends ObjectIn[QComment, T] {
lazy val question = Field.ref("question", Question.collection,
_.question)
lazy val content = Field.scalar("content", _.content, (c: QComment,
v: String) => c.content = v)
lazy override val * = question :: content :: Nil
override def factory(dbo: DBObject) = for (question(q) <- Some(dbo))
yield new QComment(q)
}

object QComment extends ObjectShape[QComment] with
QCommentIn[QComment] {}

Please help me check the code, it can't pass compilation.

On 3月20日, 下午4时45分, Alexander Azarov <aza...@aha.ru> wrote:
> 20.03.2011 at 11:41, Freewind wrote
>
> > After 1 day of tring, I have to say, it's hard to start with this
> > project. I mean, for the one-to-many, many-to-many, embedded array,
> > and so on, there is no good demo to learn.
>
> The project's Specs cover most of these:
>
> https://github.com/osinka/mongo-scala-driver/tree/master/src/test/sca...

Freewind

unread,
Mar 20, 2011, 8:54:48 AM3/20/11
to mongo-scala-driver
Since the code is hard to read in google group, I paste it in github:

https://gist.github.com/878314

Freewind

unread,
Mar 20, 2011, 9:37:23 AM3/20/11
to mongo-scala-driver
Please ignore this one. I want to create a demo project that make you
help me easier :)

Alexander Azarov

unread,
Mar 20, 2011, 9:38:31 AM3/20/11
to mongod...@googlegroups.com

20.03.2011 at 16:37, Freewind wrote:

> Please ignore this one. I want to create a demo project that make you
> help me easier :)

I appreciate it!

Reply all
Reply to author
Forward
0 new messages