title: TypeError: Collection(Database(MongoClient("localhost", 27017), u'demo_database'), u'entries) is not JSON serializable
body: <p>Good afternoon.</p>
  
  <p>I'm trying to combine Python, MongoDB (via pymongo) and Flask to create client-server application. I want to use one of methods to return all the entire collection, like here:</p>
  
  <pre><code>@app.route('/entries', methods = ['GET'])
  def get_entries():
      client = MongoClient(db_host, db_port)
      db_demo = client['demo_database']
      entries = db_demo.entries
      return JSONEncoder().encode(entries)
  </code></pre>
  
  <p>I also have an <strong>Encoder</strong> class, as advised <a href="https://stackoverflow.com/questions/16586180/typeerror-objectid-is-not-json-serializable">here</a>:</p>
  
  <pre><code>class JSONEncoder(json.JSONEncoder):
      def default(self, o):
          if isinstance(o, ObjectId):
              return str(o)
          return json.JSONEncoder.default(self, o)
  </code></pre>
  
  <p>Data collection is very simple - actually, only one item with few fields. What am I doing wrong? Perhaps I should develop more sophisticated encoder class?</p>