Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo engine query the referencefield

I have define the class statement:

from mongoengine import *
class TickDataDocument(Document):
"""
"""
    instrument_id = StringField(max_length=10, unique=True, required=True)
    tick_data = ReferenceField(TickDocument)


class TickDocument(Document):
"""
"""
    price = DecimalField(precision=2, required=True) 
    volume = LongField(required=True)  
    turnover = DecimalField(precision=2, required=True)  
    update_time = DateTimeField(unique=True, required=True)

I want to query the update_time in some period of time.

 TickDataDocument.objects(instrument_id="fa1100").filter(tick_data__ update_time__lt =datetime.datetime(2013,9,3))

but I got errors:

mongoengine.errors.InvalidQueryError: Cannot perform join in mongoDB: tick_data__update_time

How could I to five a solution to query the inner reference field in mongoengine.

like image 686
nooper Avatar asked Aug 22 '15 12:08

nooper


1 Answers

As suggested in a comment, I do this in two steps (two queries):

tick_docs = list(TickDocument.object(update_time__lt)=datetime.datetime(2013,9,3))

TickDataDocument.objects(instrument_id="fa1100").filter(tick_data__in=tick_docs)

If there is any simpler solution, I'm interested as well.

like image 159
Jérôme Avatar answered Oct 16 '22 01:10

Jérôme