Here's another answer using pymongo that always provides the relevant ID. The update() answer above only gives you the ID if the field is new.
upsert_results = MyMongoCollection._get_collection().find_and_modify(
{
'name':desiredName,
# NOTE: _cls (below) only necessary if you meta.allow_inheritance=True
'_cls': MyMongoCollection._class_name
},
{'$set': {'field1': 2}}, # always provide a $set even if {} or it will no-op.
upsert=True, full_response=True, new=True, fields=['_id'])
obj_id = upsert_results['value']['_id']
obj_created = not upsert_results['lastErrorObject']['updatedExisting']