Why do EmbeddedDocuments receive an _id ?

3 views
Skip to first unread message

Seth Ladd

unread,
Nov 18, 2009, 2:50:14 PM11/18/09
to MongoMapper
Aloha,

There may be a perfectly good reason for this, but curious what the
reason is. Whenever an EmbeddedDocument is created and assigned to a
Document, that EmbeddedDocument is given an _id.

Example:

class Project
include MongoMapper::Document
many :tasks
end

class Task
include MongoMapper::EmbeddedDocument
end

project = Project.new
project.tasks << Task.new

project.to_mongo => {"tasks"=>[{"_id"=>"4b044d92dc26b4b83c000009"}]}

I wouldn't imagine that EmbeddedDocuments have IDs, as their identity
is intimately entwined with their owning document. Just curious what
the conscious decision was behind this choice.

Thanks!
Seth

John Nunemaker

unread,
Nov 18, 2009, 3:45:53 PM11/18/09
to mongo...@googlegroups.com
Having an id makes it easy to do partial updates on embedded docs.
> --
> You received this message because you are subscribed to the Google
> Groups "MongoMapper" group.
> For more options, visit this group at
> http://groups.google.com/group/mongomapper?hl=en?hl=en

Stephen Eley

unread,
Nov 18, 2009, 4:07:05 PM11/18/09
to mongo...@googlegroups.com
On Wed, Nov 18, 2009 at 3:45 PM, John Nunemaker <nune...@gmail.com> wrote:
> Having an id makes it easy to do partial updates on embedded docs.

I can see the value of that for a lot of use cases. But for cases
where it isn't required, is it easy to disable that behavior? I can
think of uses for short, very simple embeddings where an element would
never be updated in isolation and where this id field would take up at
least as much space as the business data.


--
Have Fun,
Steve Eley (sfe...@gmail.com)
ESCAPE POD - The Science Fiction Podcast Magazine
http://www.escapepod.org

John Nunemaker

unread,
Nov 18, 2009, 4:37:12 PM11/18/09
to mongo...@googlegroups.com
Not right now.
Reply all
Reply to author
Forward
0 new messages