title: How to add data to mongoDB in python
body: <p>I am a python noob (working with it for less than a few hours).  I'm trying to read in twitter data and store it in a mongo database, but I am getting the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "twit_test.py", line 8, in on_receive
      db.posts.insert(data)
    File "/Library/Python/2.6/site-packages/pymongo-2.0.1-py2.6-macosx-10.6-universal.egg/pymongo/collection.py", line 274, in insert
    File "/Library/Python/2.6/site-packages/pymongo-2.0.1-py2.6-macosx-10.6-universal.egg/pymongo/database.py", line 249, in _fix_incoming
    File "/Library/Python/2.6/site-packages/pymongo-2.0.1-py2.6-macosx-10.6-universal.egg/pymongo/son_manipulator.py", line 73, in transform_incoming
  TypeError: 'str' object does not support item assignment
  Traceback (most recent call last):
    File "twit_test.py", line 17, in &lt;module&gt;
      conn.perform() 
  </code></pre>
  
  <p>My code is very simple:</p>
  
  <pre><code>import pycurl, json
  import pymongo
  
  STREAM_URL = "https://stream.twitter.com/1/statuses/sample.json"
  USER = "XXXXXXXX"
  PASS = "XXXXXXXX"
  def on_tweet(data):
    tweet = json.loads(data)
    db.posts.insert(tweet)
  
  from pymongo import Connection
  connection = Connection()
  db = connection.test
  conn = pycurl.Curl()
  conn.setopt(pycurl.USERPWD, "%s:%s" % (USER, PASS))
  conn.setopt(pycurl.URL, STREAM_URL)
  conn.setopt(pycurl.WRITEFUNCTION, on_tweet)
  conn.perform() 
  </code></pre>
  
  <p>I'm sure this is a VERY simple fix, hope you guys can help.  Thanks!</p>