Although your second approach should work, it docQueryis an object of type Cursor. The best way is to iterate over it, for example:
for itm in db.doctors.find({"email":doc_mail}):
print itm.get('_id')
Or, if there is only one object, use find_oneas:
itm = db.doctors.find_one({"email":doc_mail})
print itm.get('_id')
source
share