hmarr/mongoengine — Issue #452: new ObjectID in EmbeddedDocument.... 
Author: ChangMin
Created: 2012-03-03 13:37:57+00:00
State: open

class Example(EmbeddedDocument):
id = ObjectIdField(required=True)

In this case, the "id" field in EmbeddedDocument: Example doesn't have new ObjectId but just nothing.

In order to solve this problem.. I used pymongo..

from pymongo.objectid import ObjectId
Example(id=ObjectId()).save()

but the problem is that whenever I retrieve Example's id field from mongodb...
I have to transform the id field to string to send them to users by using JSON.

example = Example.objects().first()
result = str(example.id)

I think Mongoengine should automatically create new ObjectId field if it's required and then when developer request it,
Mongoengine should transform ObjectId field to string automatically..