hmarr/mongoengine — Issue #456: Need a simple way to get id of ReferenceField
Author: anti-social
Created: 2012-03-06 16:54:49+00:00
State: open

Sometimes I need to get reference field id but way I do this is ugly. As I understand if I get value of reference field there will be additional query to mongo.

So I need to write something like that:

```python
class MyDoc(Document):
other_doc = ReferenceField('AnotherDoc')

d = MyDoc.objects(id=object_id).first()
other_doc_dbref = d._data.get('other_doc')
other_doc_id = other_doc_dbref.id if other_doc_dbref else None
```

I think this should be simpler.