Reputation: 2505
Is it possible to disable _id for embedded documents?
For example if have a parent with an embedded child document. it seems kind of pointless for the child to have an id if i don't intend to reference the child from anywhere else.
class Parent
include MongoMapper::Document
one :child
key :name
end
class Child
include MongoMapper::EmbeddedDocument
key :name
end
parent = Parent.new(:name => 'parent',
:child => Child.new(:name => 'child'))
puts parent.to_json
{"id":"4ebeddde51d9e56dcb000006","name":"parent",
"child":{
"id":"4ebeddde51d9e56dcb000005",
"name":"child"}}
Upvotes: 1
Views: 175
Reputation: 9094
I remember there being talk at one point of removing the _id field for embedded one. Best bet would be to patch it yourself and then send a pull request.
Otherwise, there isn't a config option to remove the id. You might be able to over-write to_mongo, if you were adventurous.
Upvotes: 1