I posted an edit on the title of your post, given that this is somewhat misleading to the problem you are facing. You did not try to update the field _idas indicated, but your Python Dictionary definition is incompatible with the BSON specification.
:
data = {'foo': 'bar', 'baz': {1: {'a': 'B'}}, '_id': 'AB123456789'}
( ) , Mongo, . JSON, BSON, , , .
bson.errors.InvalidDocument: documents must have only string keys, key was 1
Python , .
data = {'foo': 'bar', 'baz': {'1': {'a': 'B'}}, '_id': 'AB123456789'}
.
, ( ) MongoDB .