title: How to setup models in flask with pymongo
body: <p>I want to use PyMongo directly within flask, is it possible to create <code>models.py</code> for MongoDB without ORMs? If so, is it recommended?</p>
  
  <p>I don't know how/if possible to create <code>models.py</code> so I just work with db without it</p>
  
  <p><strong>config.py</strong></p>
  
  <pre><code>class Config(object):
      # ...
      DATABASE_URI = os.environ.get('DATABASE_URI') or \
          'mongodb+srv://kay:myRealPassword@cluster0-wpeiv.mongodb.net/test'
  </code></pre>
  
  <p><strong>app/__ init __.py</strong></p>
  
  <pre><code>from flask import Flask
  from config import Config
  from pymongo import MongoClient
  
  app = Flask(__name__)
  # ...
  client = MongoClient(app.config['DATABASE_URI'])
  db = client.test
  </code></pre>
  
  <p><strong>app/routes.py</strong></p>
  
  <pre><code># ...
  from app import db
  
  users = db.users
  posts = db.posts
  
  @app.route('/')
  # ...
  </code></pre>
  
  <p>Should I just use the driver directly in my <code>routes.py</code>?</p>