烧瓶和蒙戈

发布于 2024-11-24 03:10:22 字数 159 浏览 1 评论 0原文

考虑到完全构建在 MongoDB 之上的 Web 服务,虽然我对 PyMongo 非常满意,但我想知道你们对这些 ODM 是否有任何积极或消极的经验/故事:MongoKit、MongoEngine 和 MongoAlchemy,后者有一个特定于 Flask 的包“Flask-mongoalchemy”。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南风起 2024-12-01 03:10:22

我使用 MongoEngine 和 Flask 没有问题。我们编写了(收集的资源),其中还包括 wtform 支持和 Flask-debugger 支持:

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

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/

清风挽心 2024-12-01 03:10:22

我真的没有任何真实的经验或故事可以提供,但我同时使用了 MongoKit 和 MongoAlchemy,我个人决定尝试 MongoAlchemy,因为我更喜欢它的语法(可能是由于我的 Django 传统)。

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+',)

两者都将帮助您验证数据,让您强加诸如模式之类的东西(仅在应用程序级别),并节省您的打字时间(特别是括号)。

MongoKit 更加完整。我选择 MongoAlchemy 是因为我不想一直输入 struct = {} ,并使用 con.test.example.BlogPost() 指定您的数据库和集合感觉不对(尽管你不必这样做)。

两者都尝试一下,然后选择最适合您的一个。

正如您已经提到的,有一个 Flask-MongoAlchemy 扩展,效果很好。
如果您想使用 MongoKit,优秀的 Flask 文档将立即帮助您上手:
http://flask.pocoo.org/docs/patterns/mongokit/

很棒的是,您只需可以尝试一个,如果您不喜欢它,您可以切换到另一个,或者直接使用 pymongo,而无需更改数据库中的任何内容。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文