Created
June 27, 2014 23:47
-
-
Save alexandre/6ff7824f6cd4f9c76f8a to your computer and use it in GitHub Desktop.
Converter DBRef em um document para ObjectId.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Usando mongoengine... | |
def dbref_to_objid(document): | |
''' | |
Recebe um documento como parametro e converte os DBRefs para | |
ObjectId. | |
''' | |
from bson import DBRef | |
doc_copy = document._data.copy() | |
for key, field in document._data.items(): | |
if isinstance(field, DBRef): | |
doc_copy[key] = field.id | |
return doc_copy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment