heynemann / motorengine

Motorengine is a port of MongoEngine for Tornado.
http://motorengine.readthedocs.org
204 stars 67 forks source link

how do sorting by embedded fields? #81

Closed Rey8d01 closed 5 years ago

Rey8d01 commented 9 years ago

Example code

class PostMetaDocument(BaseDocument):
    dateCreate = DateTimeField(auto_now_on_insert=True)
    dateUpdate = DateTimeField(auto_now_on_update=True)
    author = StringField()

class PostDocument(BaseDocument):
    __collection__ = "post"

    alias = StringField()
    title = StringField()
    meta = EmbeddedDocumentField(PostMetaDocument)
    text = StringField()

I want to get collection PostDocument will be sorted by meta.dateCreate How I make it via motoengine?

this syntax is not working

PostDocument().objects.order_by("meta.dateCreate", direction=-1)

because function order_by sort among fields parent document.

heynemann commented 9 years ago

I don't think it works that way right now.

Would have to implement it...

Rey8d01 commented 9 years ago

In documentation have many simple examples and have not complex examples - how works with embeded documents.

May be possible get access to MotorCursor that do query to mongodb? Because document modeling like motorengine is what I need, but I need some manipulation.

heynemann commented 9 years ago

Definitely... I'm just VERY low on spare time to work on this. If you want to take a swing at implementing a Pull Request, it would be brilliant.

Rey8d01 commented 9 years ago

I'm sorry but my knowledge is not enough for development. motorengine looks difficult for me. maybe in the future it will be easier to understand.

heynemann commented 9 years ago

Ok, as soon as I get some spare time I'll have a look.