开发者

Flask and Mongo [closed]

As it currently stands, this quest开发者_高级运维ion is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

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".


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜