Flask and Mongo [closed]
Asked Answered
E

2

17

Thinking of a web service entirely built on top of MongoDB, while I am pretty confortable with PyMongo, I would like to know if you guys have any positive or negative experiences/stories about either of these ODMs: MongoKit, MongoEngine and MongoAlchemy, the latter having a Flask specific package "Flask-mongoalchemy".

Erfert answered 13/7, 2011 at 2:33 Comment(1)
Actually is pretty confusing to have so many options as odm, wish there was an offitial odmPelagi
A
21

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.

Alexine answered 14/7, 2011 at 22:39 Comment(0)
I
22

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/

Intact answered 16/8, 2011 at 15:59 Comment(1)
Lets get this in the Python Package index, it's fantastic.Nydia
A
21

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.

Alexine answered 14/7, 2011 at 22:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.