The AGGREGATE query is used for performing aggregate() operations, via the aggregation framework.
The base syntax is: AGGREGATE <collection>. The remaining part will be used to build the aggregation pipeline.
Warning
This part is still very work-in-progress and things described below may not corespond to the actual state of the project.
Anyways, tests are being written in order to make things work this way.
Syntax: PROJECT <assignment-list>
The PROJECT command allows an “assignment list”, eg. a comma-separated list of SYMBOL = expression items, that will be used to build the map in the $project command.
Example:
AGGREGATE article
PROJECT title = 1,
stats = {
pv = '$pageViews',
foo = '$other.foo',
dpv = '$pageViews' + 10,
}
results in:
db.article.aggregate({'$project': {
'title': 1,
'stats': {
'pv': "$pageViews",
'foo': "$other.foo",
'dpv': {'$add': ["$pageViews", 10]}
},
}})
Syntax: GROUP [ BY <expression> , ] <assignment-list>
Results in: {'$group': assignment_list}.
If the BY <expression> part is present, a key named _id will be added to the assignment list before using as argument to $group.
Syntax: SELECT <sort-spec>
Results in: {'$sort': sort_spec}.
Same as in the SELECT query: a list of <field> <direction> items will be converted in a list of (field, direction) tuples.
Supported directions are ASC and DESC.