Created
July 3, 2014 19:46
-
-
Save igr-santos/ea321ae2a822facee246 to your computer and use it in GitHub Desktop.
Example execute MongoManager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
from mongo_queryset import MongoManager, InQuery, DateQuery | |
manager = MongoManager('cybergia', 'reportlab_userdocument') | |
date_gt = datetime(2014, 01, 01) | |
date_lte = datetime.today() | |
manager.project( | |
user_pk=1, predicates__predicate=1, predicates__obj=1, | |
predicates__date=1 | |
).unwind( | |
'$predicates' | |
).match( | |
predicates__predicate='tem-habito', | |
predicates__obj=InQuery('alimentacao-saudavel', 'alimentacao-ruim', | |
'praticar-esportes'), | |
predicates__date=DateQuery(gt=date_gt, lte=date_lte) | |
).group( | |
pk='$user_pk', | |
obj='$predicates.obj', | |
year=DateQuery(year='$predicates.date'), | |
month=DateQuery(month='$predicates.date') | |
).group( | |
count=True, | |
year='$_id.year', | |
month='$_id.month', | |
obj='$_id.obj' | |
).sort( | |
_id__year=1, _id__month=1 | |
).project( | |
year='$_id.year', | |
month='$_id.month', | |
object='$_id.obj', | |
count='$count', | |
_id=0 | |
) | |
print manager.execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment