Insert Data with pymongo

Roy Smith roy at panix.com
Thu Oct 20 08:54:13 EDT 2011


In article <mailman.2082.1319114061.27778.python-list at python.org>,
 4k3nd0 <4k3nd0 at googlemail.com> wrote:

> Hi guys,
> 
> i want  to insert a JSON formated String into a mongoDB. But get some
> problem with the insert to the database.
> 
> Traceback (most recent call last):
>   File "obp_import_pb.py", line 102, in <module>
>     do_import()
>   File "obp_import_pb.py", line 97, in do_import
>     collection = db.pb_mp.insert(obp_transaction_json)
>   File "/usr/lib64/python2.7/site-packages/pymongo/collection.py", line
> 274, in insert
>     docs = [self.__database._fix_incoming(doc, self) for doc in docs]
>   File "/usr/lib64/python2.7/site-packages/pymongo/database.py", line
> 249, in _fix_incoming
>     son = manipulator.transform_incoming(son, collection)
>   File "/usr/lib64/python2.7/site-packages/pymongo/son_manipulator.py",
> line 73, in transform_incoming
>     son["_id"] = ObjectId()
> TypeError: 'str' object does not support item assignment
> 
> 
> I'm using json.dumps to format a json string
> 
> 	obp_transaction_json = json.dumps(......)
> 
> I took a look about the pymongo Doc, which didn't help me a bit.
> I using Python 2.7, on a Gentoo(Linux-3.0.5) AMD64

You haven't given enough information to even guess at the problem.  Does 
the exception get thrown as part of the assignment, or evaluating the 
"....." you pass to json.dumps()?  I would start by breaking things down 
into smaller pieces and seeing which piece raises the exception.

Also, post more of your code so we can see what's going on.



More information about the Python-list mailing list