title: Insert python object in mongodb
body: <p>Folks,
  I just spent a good amount of time trying to look this up -- I ought to be missing something basic.</p>
  
  <p>I have a python object, all I want to do is to insert this object in mondodb.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>from pymongo import Connection
  import json
  
  conn = Connection()
  db = conn.cl_database
  postings = db.postings_collection
  
  class Posting(object):
      def __init__(self, link, found=None, expired=None):
          self.link = link
          self.found = found
          self.expired = expired
  
  posting = Posting('objectlink1')
  value = json.dumps(posting, default=lambda x:x.__dict__)
  postings.insert(value)
  </code></pre>
  
  <p>throws this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./mongotry.py", line 21, in &lt;module&gt;
  postings.insert(value)
    File "build/bdist.macosx-10.7-intel/egg/pymongo/collection.py", line 302, in insert
    File "build/bdist.macosx-10.7-intel/egg/pymongo/database.py", line 252, in _fix_incoming
    File "build/bdist.macosx-10.7-intel/egg/pymongo/son_manipulator.py", line 73, in transform_incoming
  TypeError: 'str' object does not support item assignment
  </code></pre>
  
  <p>Seems like it is because json.dumps() returns a string.</p>
  
  <p>Now if I do do a loads of the value before inserting it works fine:</p>
  
  <pre><code>posting = Posting('objectlink1')
  value = json.dumps(posting, default=lambda x:x.__dict__)
  value = json.loads(value)
  postings.insert(value)
  </code></pre>
  
  <p>What is the most straight-forward to do this?</p>
  
  <p>Thanks!</p>