Reputation: 3035
I have noticed a weird thing happening in my application. I just can't figure out what is the systematic error that I am doing, that makes my id field to be named None. I am using mongoengine and I defined a document such as:
class TestDoc(Document):
myField = StringField()
secondField = StringField()
Then, when I instantiate a Python object of type TestDoc this is what happens:
doc = models.TestDoc(myField="My field")
doc.save()
print doc.id
print "TESTING DOC: ", doc.__dict__
The result to this is:
>> 516d4e3cd836195263fdd45b
>> TESTING DOC: {'_created': False, '_data': {None: ObjectId('516d4e3cd836195263fdd45b'), 'secondField': None, 'myField': 'My field'}, '_changed_fields': [], '_initialised': True}
I don't understand why instead of a field named "id" I end up having a weird field called None, having as value the actual id. In the DB everything seems to be fine, the documents look ok, but as soon as I retrieve a doc and wish to process it or convert it to json in order to send it over the network, this makes me problems. Can anyone help?
Upvotes: 0
Views: 1216