2015-07-10 64 views
0

我一直想查詢一些蒙戈實例變量,Python和MongoEngine 我需要從每一個RegistroPozo得到所有變量在所有的收藏。Quering嵌套文件查詢與Mongoengine

示例代碼:

from mongoengine import * 
class Variable(EmbeddedDocument): 
    mnem=StringField(required=True, max_length=200) 
    description=StringField(max_length=500) 
    unit=StringField(max_length=200,default='ppm') 
    alias=StringField(max_length=200) #,default=mnem 
    type=StringField(max_length=200,default='DEPENDANT') 



class RegistroPozo(EmbeddedDocument): 
    fecha = DateTimeField() 
    filepath = StringField() 
    start = FloatField() 
    step = FloatField() 
    stop = FloatField() 
    variables = EmbeddedDocumentListField(Variable) 
    registros = ListField(DictField()) 
    version_information_block = StringField(max_length=500) 
    well_information_block = StringField(max_length=500) 
    curve_information_block = StringField(max_length=500) 
    parameter_information_block = StringField(max_length=500) 
    other_block = StringField(max_length=500) 


class Pozo(DynamicDocument): 
    uwi_pozo = StringField(required=True, max_length=200, primary_key=True) 
    nom_pozo = StringField(required=True, max_length=200) 
    prof_total = FloatField(required=True) 
    elev_terr = FloatField(required=True) 
    long_pozo = FloatField(required=True) 
    lat_pozo = FloatField(required=True) 
    coord_x_po = FloatField(required=True) 
    coord_y_po = FloatField(required=True) 
    registros_pozo=EmbeddedDocumentListField(RegistroPozo) 

當我嘗試查詢我做了很多圈,但我相信有一個更好的辦法做到這一點。 喜歡的東西:

variables_in_all_the_doc = Pozo.objects(Q(AdvanceQuery)) 

回答

0

波索是蒙戈分貝水平單個文檔。嵌入式文件只是mongoengine結構。因此,當您閱讀Pozo對象時,所有嵌入式文檔也可用於相同的查詢(請參閱mongostat)。現在迭代這些數據並不是一個大問題。有關高級EmbeddedDocumentList查詢,請閱讀文檔here