Insert Data with pymongo


4

4k3nd0

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


Greeting's from Germany,
Akendo
 
Ad

Advertisements

R

Roy Smith

4k3nd0 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top