0

我看到很多用于 django 的 mongodb adapetrs,但其中大多数不支持 django 1.4 或与 django orm 的语法不同。那么,对于 1.4,最好的 django 映射器是什么,希望与 django orm 的语法相同?

4

1 回答 1

0

http://mongoengine.org/看起来不错

语法如下所示:

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.
于 2012-12-29T03:10:25.863 回答