Flask and Mongo [closed] Flask and Mongo [closed] mongodb mongodb

Flask and Mongo [closed]


I use MongoEngine with flask no problems. We've written (collected resources) which include wtform support and flask-debugger support as well:

https://github.com/MongoEngine/flask-mongoengine/


I don't really have any real experience or story to offer, but i played with both MongoKit and MongoAlchemy, and i personally decided to try MongoAlchemy, because i like the syntax a little better (probably due to my Django heritage).


MongoKit:

class BlogPost(Document):    structure = {                'title':unicode,                'body':unicode,                'author':unicode,                'date_creation':datetime.datetime,                'rank':int                }


MongoAlchemy:

class BloodDonor(Document):    first_name = StringField()    last_name = StringField()    age = IntField(min_value=0)    gender = EnumField(StringField(), 'male', 'female')    blood_type = EnumField(StringField(), 'O+','A+','B+','AB+',)


Both will help you to validate your data, will let you impose something like a schema (only on application level), and will save you some typing (specifically brackets).

MongoKit is more complete. I chose MongoAlchemy because I didn't want to type structure = {} all the time, and specifying your db and collection using con.test.example.BlogPost() just felt wrong (although you don't have to do it this way).

Try both, and choose the one which works better for you.

As you already mentioned, there is a Flask-MongoAlchemy extension, which works great.If you want to use MongoKit, the excellent Flask documentation will get you going in no time:http://flask.pocoo.org/docs/patterns/mongokit/

The great thing is that you just can try one, if you don't like it you can switch to another, or drop to pymongo without having to change anything in the database.