How to push into array nested in dictionary?
Question: I want to create a mongodb to store the homework results, I create a
`homework` which is a dictionary storing the results' array of each subject.

    
    
    import pymongo
    
    DBCONN = pymongo.Connection("127.0.0.1", 27017)
    TASKSINFO = DBCONN.tasksinfo
    
    _name = "john"
    taskid = TASKSINFO.tasksinfo.insert(
        {"name": _name,
         "homework": {"bio": [], "math": []}
         })
    
    TASKSINFO.tasksinfo.update({"_id": taskid},
                               {"$push": {"homework.bio", 92}})
    

When I tried to push some information to db, there's error:

    
    
    Traceback (most recent call last):
      File "mongo_push_demo.py", line 13, in <module>
        {"$push": {"homework.bio", 92}})
      File "/usr/local/lib/python2.7/dist-packages/pymongo-2.5-py2.7-linux-i686.egg/pymongo/collection.py", line 479, in update
        check_keys, self.__uuid_subtype), safe)
      File "/usr/local/lib/python2.7/dist-packages/pymongo-2.5-py2.7-linux-i686.egg/pymongo/message.py", line 110, in update
        encoded = bson.BSON.encode(doc, check_keys, uuid_subtype)
      File "/usr/local/lib/python2.7/dist-packages/pymongo-2.5-py2.7-linux-i686.egg/bson/__init__.py", line 567, in encode
        return cls(_dict_to_bson(document, check_keys, uuid_subtype))
      File "/usr/local/lib/python2.7/dist-packages/pymongo-2.5-py2.7-linux-i686.egg/bson/__init__.py", line 476, in _dict_to_bson
        elements.append(_element_to_bson(key, value, check_keys, uuid_subtype))
      File "/usr/local/lib/python2.7/dist-packages/pymongo-2.5-py2.7-linux-i686.egg/bson/__init__.py", line 466, in _element_to_bson
        type(value))
    bson.errors.InvalidDocument: cannot convert value of type <type 'set'> to bson
    


Answer: 
    {"$push": {"homework.bio", 92}})
    

It should be `:`, not `,`.

`{'a', 1}` is a set of two elements in Python, that's why you get the error.

