Mongoengine 简明教程

MongoEngine - Object Document Mapper

MongoDB 是基于文档的数据库。每个文档都是字段和值的 JSON 类似表示。MongoDB 中的文档大致等效于 RDBMS 表中的行(MongoDB 等效的表是集合)。尽管 MongoDB 不强制使用任何预定义架构,但文档中的字段对象具有一定数据类型。MongoDB 数据类型与 Python 的主数据类型非常相似。如果必须存储 Python 的用户定义类的对象,则必须手动将其属性解析为等效的 MongoDB 数据类型。

MongoDB is a document based database. Each document is a JSON like representation of fields and values. A document in MongoDB is roughly equivalent to a row in RDBMS table (MongoDB equivalent of table is Collection). Even though MongoDB does not enforce any predefined schema, the field objects in a document have certain data type. MongoDB data types are very much similar to Python’s primary data types. If one has to store object of Python’s user defined class, its attributes have to be manually parsed to equivalent MongoDB data types.

MongoEngine 在 PyMongo 上提供了一个便捷的抽象层,并将 Document 类的每个对象映射到 MongoDB 数据库中的一个文档。MongoEngine API 是由 Hary Marr 在 2013 年 8 月制定的。MongoEngine 的最新版本是 0.19.1。

MongoEngine provides a convenient abstraction layer over PyMongo and maps each object of Document class to a document in MongoDB database. MongoEngine API has been developed by Hary Marr in August 2013. Latest version of MongoEngine is 0.19.1.

MongoEngine 之于 MongoDB,正如 SQLAlchemy 之于 RDBMS 数据库。MongoEngine 库提供了一个 Document 类,该类用作定义自定义类的基础。该类的属性形成 MongoDB 文档的字段。Document 类定义执行 CRUD 操作的方法。在后续主题中,我们将学习如何使用它们。

MongoEngine is to MongoDB what SQLAlchemy is to RDBMS databases. MongoEngine library provides a Document class that is used as base for defining custom class. Attributes of this class form the fields of MongoDB document. The Document class defines methods to perform CRUD operations. In subsequent topics, we shall learn how to use them.