title: Getting 'TypeError: ObjectId('') is not JSON serializable' when using Flask 0.10.1
body: <p>I forked the Flask example, Minitwit, to work with MongoDB and it was working fine on Flask 0.9, but after upgrading to 0.10.1 I get the error in title when I login when I try to set the session id.</p>
  
  <p>It seems there was <a href="http://lucumr.pocoo.org/2013/6/13/werkzeug-and-flask-releases/" rel="nofollow noreferrer">changes</a> in Flask 0.10.1 related to json.</p>
  
  <p>Code snippet:</p>
  
  <pre><code>user = db.minitwit.user.find_one({'username': request.form['username']})
  session['_id'] = user['_id']
  </code></pre>
  
  <p>Full code in my <a href="https://github.com/admiralobvious/minitwit-mongodb/blob/master/minitwit.py" rel="nofollow noreferrer">github</a> repo.</p>
  
  <p>Basically, I set the Flask session id to the user's _id from MongoDB.</p>
  
  <p>I tried the first two solution from this <a href="https://stackoverflow.com/questions/11875770/how-to-overcome-datetime-datetime-not-json-serializable-in-python">SO question</a> without success.</p>
  
  <p>Well, doing session['_id'] = str(user['_id']) gets rid of the error message and I'm properly redirected to the timeline page but I am not actually logged in.</p>
  
  <p>How can I fix this?</p>
  
  <p>EDIT: Copy/paste of the traceback: <a href="http://pastebin.com/qa0AL1fk" rel="nofollow noreferrer">http://pastebin.com/qa0AL1fk</a></p>
  
  <p>Thank you.</p>