python - Using MongoEngine for Django, how do I filter the QuerySet by the size of a list and greater than a value? -
i using django 1.6.8 , mongoengine 0.8.2.
i have 2 classes, servicedocument , optiondocument. servicedocument keeps list of optiondocuments. there millions of servicedocuments (2.5 million +).
i want select every servicedocument has more 2 optiondocuments.
i "want" work, 0 result:
servicedocument.objects.filter(options__size__gt=2).count()
this work:
>>> servicedocument.objects.filter(options__size=1).count() 6582 >>> servicedocument.objects.filter(options__size=2).count() 2734321 >>> servicedocument.objects.filter(options__size=3).count() 25165 >>> servicedocument.objects.all().count() 2769768
lastly, if had fewer servicedocuments and/or iterator working loop through them myself, segfaults after memory fills after few seconds (i'm guessing operation on .all() try collect them in memory).
for iterator, tried following without success:
iter(servicedocument.objects.all())
well think need find work around mongoengine doesn't support query. can add field 'options_length' , store length of options field in this. can query using '__gt > 2'. additional cost need override model save function update length on every save. need update existing records this.
you can read question
Comments
Post a Comment