Objekt-ID importieren:
from bson import ObjectId
Von ObjectId zu String:
oid = ObjectId()
oid_str = str(oid)
# oid_str is now '555fc7956cda204928c9dbab'
Von Zeichenfolge zu ObjectId:
oid_str = '555fc7956cda204928c9dbab'
oid2 = ObjectId(oid_str)
print(repr(oid2))
# ObjectId('555fc7956cda204928c9dbab')