Insert a document with Flask-PyMongo
<p>I have a MongoDB database and I want to use Flask-PyMongo to work with it in my Flask app.  How do I add a database and a collection so I can add user documents?</p>

<pre><code>from flask import Flask, render_template, url_for
from flask.ext.pymongo import PyMongo

app = Flask(__name__)
app.config['MONGO_DBNAME'] = 'microblogdb'
app.config['MONGO_URI'] = 'mongodb://briangunsel:password@microblog:27017/microblogdb'
mongo = PyMongo(app, config_prefix='MONGO')


@app.route('/')
def home():
    posts = mongo.db.posts.find({})
    return render_template('users.html', posts=posts)

app.run(debug=True)
</code></pre>

<p>Update:
With only that code above, when I start up the server (python <strong>init</strong>.py) and I go to load the web page, it loads for about 10 seconds and then gives me this error <a href="https://gist.github.com/anonymous/62ca41e98e67b304838d" rel="nofollow">https://gist.github.com/anonymous/62ca41e98e67b304838d</a>. I am running the database <code>microblogdb</code> in another cmd prompt, and I set the mongo --dbpath to \data\, which is a folder I created in the microblog folder. Through the mongo interpreter, I added a <code>posts</code> collection, it is still giving me the same error.</p>