简体   繁体   English

有没有办法使用 Motor 定义 MongoDB 模式?

[英]Is there a way to define a MongoDB schema using Motor?

There is a way to define MongoDB collection schema using mongoose in NodeJS.有一种方法可以在 NodeJS 中使用 mongoose 定义 MongoDB 集合模式。 Mongoose verifies the schema at the time of running the queries. Mongoose 在运行查询时验证架构。

I have been unable to find a similar thing for Motor in Python/Tornado.我一直无法在 Python/Tornado 中为 Motor 找到类似的东西。 Is there a way to achieve a similar effect in Motor, or is there a package which can do that for me?有没有办法在 Motor 中实现类似的效果,或者是否有可以为我做到这一点的软件包?

No there isn't.不,没有。 Motor is a MongoDB driver, it does basic operations but doesn't provide many conveniences. Motor 是一个 MongoDB 驱动程序,它执行基本操作,但没有提供很多便利。 An Object Document Mapper (ODM) library like MongoTor, built on Motor, provides higher-level features like schema validation.像 MongoTor 这样的对象文档映射器 (ODM) 库构建在 Motor 上,提供了更高级别的功能,例如模式验证。

I don't vouch for MongoTor.我不担保 MongoTor。 Proceed with caution.谨慎行事。 Consider whether you really need an ODM: mongodb's raw data format is close enough to Python types that most applications don't need a layer between their code and the driver.考虑一下您是否真的需要 ODM:mongodb 的原始数据格式与 Python 类型足够接近,以至于大多数应用程序不需要它们的代码和驱动程序之间的层。

Currently (2019) this project Umongo https://github.com/Scille/umongo seems the more active and usefull if you need a sync/async Python MongoDB ODM.目前(2019 年)这个项目 Umongo https://github.com/Scille/umongo如果你需要一个同步/异步 Python MongoDB ODM 似乎更活跃和有用。 It work with multiple drivers like PyMongo or Motor for async.它可以与多个驱动程序一起使用,例如 PyMongo 或 Motor 以实现异步。 Doc is here: http://umongo.readthedocs.io文档在这里: http : //umongo.readthedocs.io

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM