MongoEngine
The object-document mapper to connect Python and MongoDB
MongoEngine is a Document-Object Mapper (think ORM, but for document databases) for working with MongoDB from Python. It uses a simple declarative API, similar to the Django ORM.
Documentation available at http://bit.ly/mongoengine-docs - there is currently a tutorial, a user guide and API reference.
from mongoengine import * # To define a schema for a
# document, we create a
class Metadata(EmbeddedDocument): # class that inherits from
tags = ListField(StringField()) # Document.
revisions = ListField(IntField()) #
# Fields are specified by
class WikiPage(Document): # adding field objects as
title = StringField(required=True) # class attributes to the
text = StringField() # document class.
metadata = EmbeddedDocumentField(Metadata) #
# Querying is achieved by
>>> page.title = "Hello, World!" # calling the objects
>>> for page in WikiPage.objects: # attribute on a document
>>> print page.title # class.
v0.6.8 Released
Multiple minor fixes and added choices to GenericEmbeddedDocuments and GenericReferences. See the change log for a full list of changes.
v0.6.7 Released
Fixes for replicaset connections and read preferences now supported. Added support for _id in indexing. Auto creation of indexes is now configurable.
v.0.6.6 Released
Mostly has bug fixes and adds support for both Django 1.3 and Django 1.4 Upgrade today!
Roadmap released
The roadmap has been planned to get us to a 1.0 release. The features coming up in 0.7 are:
- Performance - Dirty data tracking
- Allow inheritance default to off
- Chainable QuerySet slice
- Serialization / deserialization
- Raw method for pyMongo
MongoEngine v0.6 Released
Just to let you know 0.6 has been released! Another massive changelog but the big items are:
- Sharding support - through the shard_key meta data.
- ReplicaSet Support - You can now connect to replica sets for slave okay reads.
- Dynamic Documents - A new base class for documents that allows fully dynamic documents (or embedded documents) with expando style attribute setting.
- PyMongo 2.2 support - PyMongo imports now cleaned up for PyMongo 2.2 support.
Other improvements worth a mention are: ImageField, scalar values, $elementMatch support, URI connection support and many more small bugfixes and improvements.
See the upgrade docs - for information on how best to update your application.
Getting Started
To install MongoEngine, simply run:
pip install mongoengine
Downloads are also available as .zip/.tar.gz archives for the stable and master versions.
To get to grips with MongoEngine, there is extensive documentation, API references and a tutorial. You can find help by joining the MongoEngine Users mailing list or by chatting with other users on the #mongoengine IRC channel.
If you are interested in contributing, join the developers' mailing list.
Source
The source code is available for download under the MIT License over at GitHub. To checkout the latest version using git, clone the mainrepository:
git clone https://github.com/MongoEngine/mongoengine.git
Contributing
To contribute to the project, fork it on GitHub and send a pull request, all contributions and suggestions are welcome!