Re: How to design such a class?

6 views
Skip to first unread message
Message has been deleted
Message has been deleted

Alexander Azarov

unread,
Mar 21, 2011, 1:52:59 PM3/21/11
to mongod...@googlegroups.com
You can create ObjectID and save it along with Comment object, I see no problem with this -- but you will have to do it on your own, since MongoDB does not provide _id for embedded documents.

21.03.2011 at 10:42, Freewind wrote:

> You can see:
>
> https://github.com/freewind/mongo-scala-demo/blob/master/src/main/scala/Question.scala
>
> and
>
> https://github.com/freewind/mongo-scala-demo/blob/master/src/test/scala/question_tests.scala
>
> to know what exactly what I mean
>
> On 3月21日, 下午3时38分, Freewind <nowind...@gmail.com> wrote:
>> I want to design a class named `Question` with some comments of it. At
>> first, I use `refArray`, that all comments are stored in a seperated
>> collection named `question_comments`. It looks like:
>>
>> Question:
>> _id: ObjectId
>> title:String
>> content:String
>>
>> QuestionComment:
>> _id: ObjectId
>> content: String
>> question_ref: ObjectId
>>
>> Each comment has a "_id", that I can find or edit or delete a comment
>> easily.
>>
>> But someone said we should keep the information into a single document
>> as possible as we can (for performance), so I want to embed comments
>> into questions
>>
>> Question:
>> _id:ObjectId
>> title:String
>> content:String
>> comments: [
>> comment
>> _id: ObjectId
>> content: String
>> question_ref: ObjectId
>> ]
>>
>> You can see what I want is store a "_id" and question_ref in each
>> comment. So I can get/edit/delete any comment easily, or get the
>> question it belongs to.
>>
>> But I followed the wiki, found the comments embeded in question only
>> contains a `content` field, no `_id` nor `question_ref`. How to define
>> them?
>>
>> I have read the wiki and `pocketchangeapp`, but now found what I want.
>> Is it possible to do with scala-mongo-driver?
>
>

Reply all
Reply to author
Forward
0 new messages